smtp
> Documentation > Docs > INFINI Gateway > References > Offline Processor > smtp

smtp #

Description #

The SMTP processor is used to send emails, supporting both plain text and HTML emails. It supports template variables and allows attachments to be embedded in the email body. The email message is comes from the pipeline context.

Configuration Example #

A simple example is as follows:

pipeline:
  - name: send_email
    auto_start: true
    keep_running: true
    retry_delay_in_ms: 5000
    processor:
      - consumer:
          consumer:
            fetch_max_messages: 1
          max_worker_size: 200
          num_of_slices: 1
          idle_timeout_in_seconds: 30
          queue_selector:
            keys:
              - email_messages
          processor:
            - smtp:
                idle_timeout_in_seconds: 1
                server:
                  host: "smtp.ym.163.com"
                  port: 994
                  tls:  true
                auth:
                  username: "notify-test@infini.ltd"
                  password: "xxx"
                sender: "notify-test@infini.ltd"
                recipients:
                #                  to: ["Test <medcl@infini.ltd>"]
                #                  cc: ["INFINI Labs <hello@infini.ltd>"]
                variables: #default variables, can be used in templates
                  license_code: "N/A"
                templates:
                  trial_license:
                    subject: "$[[name]] 您好,请查收您的免费授权信息! [INFINI Labs]"
                    #                    content_type: 'text/plain'
                    #                    body: "$[[name]] 您好,请查收您的免费授权信息! [INFINI Labs]"
                    content_type: 'text/html'
                    body_file: '/Users/medcl/go/src/infini.sh/ops/assets/email_templates/send_trial_license.html'
#                    attachments: #use cid in html: <img width=100 height=100 id="1" src="cid:myimg1">
#                      - file: '/Users/medcl/Desktop/WechatIMG2783.png'
#                        content_type: 'image/png'
#                        cid: 'myimg1'

Message Format #

The SMTP filter retrieves email information to be sent from the context, such as the recipient, which email template to use, and the variable parameters for the email template. The message format is fixed, and the result is as follows:

{
  "template": "trial_license",
  "email":["medcl@example.com"],
  "variables": {
    "name": "Medcl",
    "company": "INFINI Labs",
    "phone": "400-139-9200"
  }
}

The field template represents the template to be used from the configuration. email represents the recipient information of the email. variables defines the variable information to be used in the template.

Parameter Description #

NameTypeDescription
dial_timeout_in_secondsintTimeout duration for sending emails
server.hoststringEmail server address
server.portintEmail server port
tlsboolWhether to enable TLS encryption for transmission
auth.usernamestringEmail server access username
auth.passwordstringEmail server access password
senderstringSender’s email address (defaults to auth.username)
recipients.toarrayRecipients' email addresses (optional)
recipients.ccarrayCC recipients' email addresses (optional)
recipients.bccarrayBCC recipients' email addresses (optional)
templates[NAME].content_typestringEmail type, either text/plain or text/html
templates[NAME].subjectstringEmail subject, supports template variables
templates[NAME].bodystringEmail body, supports template variables
templates[NAME].body_filestringEmail body from a file, supports template variables
templates[NAME].attachments[i].cidstringAttachment CID for referencing in the body
templates[NAME].attachments[i].filestringAttachment file path
templates[NAME].attachments[i].content_typestringAttachment file type, see: http://en.wikipedia.org/wiki/MIME
message_fieldstringSource field for variables (defaults to message_field)
variable_start_tagstringVariable tag prefix (defaults to $[[)
variable_end_tagstringVariable tag suffix (defaults to ]])
variablesarrayBuilt-in variables that can be overridden by context variables