Module xw.mail

Mail client


Usage:

local mail = require 'xw.mail'

Type xw.mail

xw.mail.send(recipients, object, text, encoding, options, attachments) Send mail to some recipients in text format Requires a couple of tables to provide recipients to write to and options that will overwrite the default ones.
The recipients parameters is a matrix containing up to three tables, respectively 'to', 'cc' and 'bcc'.
xw.mail.sendHtml(recipients, object, html, encoding, options, attachments) Send mail to some recipients in HTML format
See xw.mail.send() method for parameter details

Type xw.mail

Field(s)

xw.mail.send(recipients, object, text, encoding, options, attachments)
Send mail to some recipients in text format Requires a couple of tables to provide recipients to write to and options that will overwrite the default ones.
The recipients parameters is a matrix containing up to three tables, respectively 'to', 'cc' and 'bcc'.
In each of them we'll list one or more email addess separed by ';' as follows

  {
    to = "mail_1@aaaa.com;mail_1@bbbb.com;mail_1@cccc.com",
    cc = "mail_2@aaaa.com;mail_2@bbbb.com;mail_2@cccc.com",
    bcc = "mail_3@aaaa.com;mail_3@bbbb.com;mail_3@cccc.com",
  }

The other table is for options that will overwrite the default ones. Here's an example

  {
    active = true,                 -- To switch on/off service
    sourceDomain = 'www.3di.it',
    from = 'admin@3di.it',         -- Admin email it will figure in mail as sender mail
    user = nil,                    -- Admin smtp user name if login enabled nil otherwise
    password = nil,                -- Admin smtp password if login enabled nil otherwise
    server = 'smtp.gmail.com',     -- smtp server host
    port = 25,                     -- smtp server port {25 | 465}
    ssl = true                     -- true if there is an ssl communication { true | false }
  }

The caller is not required to give all values but only the ones he wants to overwrite.

Parameters

  • #table recipients : Table of the email addresses to send mail to
  • #string object : Email object
  • #string text : Email message in txt format
  • #string encoding : Encoding of object and text value. Utf-8 default
  • #table options : Options that will be applied. Pay attention: once set this values will be used in any following call
    until a new set of options will be provided.
  • #table attachments : A table of full file names and mime types

Return values

  1. #boolean: true if the mail has been sent, false in any other case, even if mail sender is switched off
  2. #string: A message explaining the failure causes, if any, or "ok" in any other case
xw.mail.sendHtml(recipients, object, html, encoding, options, attachments)
Send mail to some recipients in HTML format
See xw.mail.send() method for parameter details

Parameters

  • #table recipients : Table of the email addresses to send mail to
  • #string object : Email object
  • #string html : Email message in HTML format
  • #string encoding : Encoding of object and text value. Utf-8 default
  • #table options : Options that will be applied. Pay attention: once set this values will be used in any following call
    until a new set of options will be provided.
  • #table attachments : A table of full file names and mime types

Return values

  1. #boolean: true if the mail has been sent, false in any other case, even if mail sender is switched off
  2. #string: A message explaining the failure causes, if any, or "ok" in any other case