Simple wrapper around luasoket smtp.send
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
cmake
docs
lua
rockspecs
CMakeLists.txt
LICENCE.txt
README.md
dist.info
sendmail.ldoc

README.md

lua-sendmail

Licence

Simple wrapper around luasoket smtp.send.
See documentation.

Usage

local sendmail = require "sendmail"
local from, to, server = 'from@some.mail', 'to@some.mail', '127.0.0.1'

sendmail(from, to, server, {"Subject", [[
  This is mail body.
]],
  file = {
    name = 'message.txt';
    data = 'file content';
  };
})

Send mail with SSL/TLS connection (using LuaSec)

sendmail{
  server = {
    ssl = {
      protocol = "sslv3",
      verify   = {"peer", "fail_if_no_peer_cert"},
      options  = {"all", "no_sslv2"},
    },
    address  = ...;
    user     = ...;
    password = ...;
  },
  ...
}

Send mail with SSL/TLS connection (using custom SSL connection)

-- I use lua-lluv-ssl library.
local ut     = require "lluv.utils"
local ssl    = require "lluv.ssl"
local socket = require "lluv.ssl.luasocket"

-- this is asyncronus call
ut.corun(sendmail, {
  server = {
    ssl = ssl.context{
      protocol = "sslv3",
      verify   = {"peer", "fail_if_no_peer_cert"},
      options  = {"all", "no_sslv2"},
    },
    create = socket.ssl;
    address  = ...;
    user     = ...;
    password = ...;
  },
  ...
})

Send attached files as single zip archive

local ZipWriter = require "ZipWriter"

sendmail{
  ...
  message = {
    ...
    file = {
      source = ZipWriter.source(ZipWriter.new(), {
        {"file01.txt", "path/to/file01.txt"},
        {"file02.txt", "path/to/file02.txt"},
      }),
      name = 'files.zip';
    }
  }
}

Dependences

  • LuaSocket
  • LuaSec - to support SMTPS protocol
  • Lua-cURL - can be used to handle SMTP(S) protocol and IO. Still require LuaSocket to build message itself