Email Alerts and Notifications

Sending an Email from Lua


Sending an email using the Translator is easy with the built in SMTP facility:

function main(Data)
   -- Set up the parameters to be used with sending an email
   local smtpparams={
      header = {To = ''; 
                From = ''; 
                Date = 'Thu, 23 Aug 2001 21:27:04 -0400';
                Subject = 'Test Subject';},
      username = 'user',
      password = 'password',
      server = 'smtp://',
      -- note that the "to" param is actually what is used to send the email, 
      -- the entries in header are only used for display. 
      -- For instance, to do Bcc, add the address in the  'to' parameter but 
      -- omit it from the header.
      to = {'',''},
      from = 'Test User <>',
      body = 'This is the test body of the email',
      use_ssl = 'try'


As always auto-completion and help are close at hand:

Some commonly used header fields are:

Header Field Description Comment
From: The email address, and optionally the name of the author(s). In many email clients this cannot be changed except by changing account settings. Mandatory
To: The email address(es), and optionally name(s) of the message’s recipient(s). Indicates primary recipients (multiple allowed), for secondary recipients see Cc: and Bcc: below.
Subject: A brief summary of the topic of the message.
Date: The local time and date when the message was written. Like the “From:” field, many email clients fill this in automatically when sending. The recipient’s client may then display the time in the format and time zone local to him/her. Mandatory
Message-ID: Also an automatically generated field; used to prevent multiple delivery and for reference in In-Reply-To: (see below).
Bcc: Blind Carbon Copy; addresses added to the SMTP delivery list but not (usually) listed in the message data, remaining invisible to other recipients.
Cc: Carbon copy; Many email clients will mark email in your inbox differently depending on whether you are in the To: or Cc: list.
Content-Type: Information about how the message is to be displayed, usually a MIME type. Non-standard
In-Reply-To: Message-ID of the message that this is a reply to. Often used to link related messages together.
Precedence: Commonly with values “bulk”, “junk”, or “list”; used to indicate that automated “vacation” or “out of office” responses should not be returned for this mail, e.g. to prevent vacation notices from being sent to all other subscribers of a mailing list. Non-standard
Received: Tracking information generated by mail servers that have previously handled a message, in reverse order (last handler first).
References: Message-ID of the message that this is a reply to, and the message-id of the message the previous was reply a reply to, etc.
Reply-To: Address that should be used to reply to the message.
Sender: Address of the actual sender acting on behalf of the author listed in the From: field (secretary, list manager, etc.).
Return-Path: When the delivery SMTP server makes the “final delivery” of a message, it inserts a return-path line at the beginning of the mail data. This use of return-path is required; mail systems MUST support it. The return-path line preserves the information in the from the MAIL command.
Errors-To: Indicates where error messages should be sent. In the absence of this line, they go to “Sender:”, and absent that, “From:”. Non-standard
X-* No standard header field will ever begin with the characters “X-“, so application developers are free to use them for their own purposes. Extensions

Tip: Fields like “X-Sender:” and “X-Mailer:” are common, but they are not part of the standard. In fact, any header fields not expressly defined in the RFC, is allowed, and ignored by most e-mail systems. So, we could have an e-mail message that uses headers like:


X-Mailer: QUALCOMM Windows Eudora Version 4.3.2

Date: Thu, 23 Aug 2001 21:27:04 -0400

From: Test User <>

Sender: <>

In-Reply-To: <>
Favorite-Color: Red

Cocktail: Martini, up, olive

Subject: test

Additional Information

  • Wikipedia: Email provides a good overview, with many links to RFCs etc.
  • RFC 5321 is the current email standard
  • RFC 5322 is the current email message standard, with header fields
  • RFC 4021 is a older standard containing mail and MIME header fields (including some fields omitted from 5322)

One Comment

  1. Pingback: Auto-Generating Code for Easy Reporting and Alerts

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.