Signed-off-by: Luan Shengde luanshengde2@huawei.com --- container/send-internet-mail/start | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 container/send-internet-mail/start
diff --git a/container/send-internet-mail/start b/container/send-internet-mail/start new file mode 100755 index 0000000..fd2267f --- /dev/null +++ b/container/send-internet-mail/start @@ -0,0 +1,76 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'set' +require_relative '../defconfig' + +docker_rm 'send-internet-mail' + +names = Set.new %w[ + ROBOT_EMAIL_INTERNET_PASSWORD + ROBOT_EMAIL_INTERNET_ADDRESS + SEND_INTERNET_MAIL_PORT +] + +defaults = relevant_defaults(names) + +ROBOT_EMAIL_ADDRESS = defaults['ROBOT_EMAIL_INTERNET_ADDRESS'] +ROBOT_EMAIL_PASSWORD = defaults['ROBOT_EMAIL_INTERNET_PASSWORD'] +SEND_MAIL_PORT = defaults['SEND_INTERNET_MAIL_PORT'] +SMTP_REGION = 'internet-smtp' + +cmd = %W[ + docker run + --restart=always + --name=send-internet-mail + -d + -e ROBOT_EMAIL_ADDRESS=#{ROBOT_EMAIL_ADDRESS} + -e ROBOT_EMAIL_PASSWORD=#{ROBOT_EMAIL_PASSWORD} + -e CCI_SRC=/c/compass-ci + -e SEND_MAIL_PORT=#{SEND_MAIL_PORT} + -e SMTP_REGION=#{SMTP_REGION} + -p #{SEND_MAIL_PORT}:#{SEND_MAIL_PORT} + -v #{ENV['CCI_SRC']}:/c/compass-ci + -v /etc/localtime:/etc/localtime:ro + -w /c/compass-ci + --log-driver json-file + send-internet-mail +] +cmd += ['ruby', "container/send-internet-mail/run.rb"] + +system(*cmd) + +puts <<EOF +port: +--- +data='{ +"subject": "email subject", +"to": "email_to_addr", +"body": "email message" +}' + +or + +data=" +subject: email subject +to: email_to_addr +body: email message" + +Usage: + curl -XPOST 'send-mail-server:11312/send_mail_yaml' -d "$data" + +--- +data=" +To: email_to_addr +Subject: email_subject + +mail_msg_line1 +mail_msg_line2 +... +" + +Usage: + curl -XPOST 'send-mail-server:11312/send_mail_text' -d "$data" +EOF