webmcp

diff framework/env/net/send_mail.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children 4fb227630097
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/net/send_mail.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +--[[--
     1.5 +net.send_mail{
     1.6 +  envelope_from = envelope_from,   -- envelope from address, not part of mail headers
     1.7 +  from          = from,            -- From     header address or table with 'name' and 'address' fields
     1.8 +  sender        = sender,          -- Sender   header address or table with 'name' and 'address' fields
     1.9 +  reply_to      = reply_to,        -- Reply-To header address or table with 'name' and 'address' fields
    1.10 +  to            = to,              -- To       header address or table with 'name' and 'address' fields
    1.11 +  cc            = cc,              -- Cc       header address or table with 'name' and 'address' fields
    1.12 +  bcc           = bcc,             -- Bcc      header address or table with 'name' and 'address' fields
    1.13 +  subject       = subject,         -- subject of e-mail
    1.14 +  multipart     = multipart_type,  -- "alternative", "mixed", "related", or nil
    1.15 +  content_type  = content_type,    -- only for multipart == nil, defaults to "text/plain"
    1.16 +  binary        = binary,          -- allow full 8-bit content
    1.17 +  content       = content or {     -- content as lua-string, or table in case of multipart
    1.18 +    {
    1.19 +      multipart = multipart_type,
    1.20 +      ...,
    1.21 +      content   = content or {
    1.22 +        {...}, ...
    1.23 +      }
    1.24 +    }, {
    1.25 +      ...
    1.26 +    },
    1.27 +    ...
    1.28 +  }
    1.29 +}
    1.30 +
    1.31 +This function sends a mail using the /usr/sbin/sendmail command.
    1.32 +
    1.33 +--]]--
    1.34 +
    1.35 +function net.send_mail(args)
    1.36 +  local mail
    1.37 +  if type(args) == "string" then
    1.38 +    mail = args
    1.39 +  else
    1.40 +    mail = encode.mime.mail(args)
    1.41 +  end
    1.42 +  local envelope_from = args.envelope_from
    1.43 +  local command
    1.44 +  if
    1.45 +    envelope_from and
    1.46 +    string.find(envelope_from, "^[0-9A-Za-z%.-_@0-9A-Za-z%.-_]+$")
    1.47 +  then
    1.48 +    command =
    1.49 +      "/usr/sbin/sendmail -t -i -f " ..
    1.50 +      envelope_from ..
    1.51 +      " > /dev/null 2> /dev/null"
    1.52 +  else
    1.53 +    command = "/usr/sbin/sendmail -t -i > /dev/null 2> /dev/null"
    1.54 +  end
    1.55 +  trace.debug(command)
    1.56 +  -- TODO: use pfilter
    1.57 +  local sendmail = assert(io.popen(command, "w"))
    1.58 +  sendmail:write(mail)
    1.59 +  sendmail:close()
    1.60 +end

Impressum / About Us