Home

Awesome

lua-resty-smtp

I must be crazy trying to send mail with Nginx.

Purpose

To make Nginx a bridge between HTTP and SMTP.

Using lua-resty-smtp in your lua code under Nginx, you just need to issue a HTTP request with your handy HTTP client (curl, wget, urllib2 from Python etc.), in order to send a mail to your SMTP server.

Features

APIs

lua-resty-smtp is API-compatible with socket.smtp from LuaSocket 2.0.2, and you can check SMTP for detailed reference of it.

And to support SSL connection to SMTP server, optional parameter ssl is added:

Extra filters

In addtion to the low-level filters provided by LuaSocket, two more filters is provided:

Installation

make install

or

luarocks install --local rockspec/resty.smtp-0.0.3-1.rockspec

Example

local config = require("config")
local smtp = require("resty.smtp")
local mime = require("resty.smtp.mime")
local ltn12 = require("resty.smtp.ltn12")

-- ...
-- Suppose your mail data in table `args` and default settings
-- in table `config.mail`
-- ...

local mesgt = {
    headers= {
        subject= mime.ew(args.subject or config.mail.SUBJECT, nil,
                         { charset= "utf-8" }),
        ["content-transfer-encoding"]= "BASE64",
        ["content-type"]= "text/plain; charset='utf-8'",
    },

    body= mime.b64(args.body)
}

local ret, err = smtp.send {
    from= args.from or config.mail.FROM,
    rcpt= rcpts,
    user= args.user or config.mail.USER,
    password= args.password or config.mail.PASSWORD,
    server= args.server or config.mail.SERVER,
    domain= args.domain or config.mail.DOMAIN,
    source= smtp.message(mesgt),
}

NOTICES:

TODO

Performance

Your SMTP server is the bottleneck. :)

Known Issues