webmcp

view 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 source
1 --[[--
2 net.send_mail{
3 envelope_from = envelope_from, -- envelope from address, not part of mail headers
4 from = from, -- From header address or table with 'name' and 'address' fields
5 sender = sender, -- Sender header address or table with 'name' and 'address' fields
6 reply_to = reply_to, -- Reply-To header address or table with 'name' and 'address' fields
7 to = to, -- To header address or table with 'name' and 'address' fields
8 cc = cc, -- Cc header address or table with 'name' and 'address' fields
9 bcc = bcc, -- Bcc header address or table with 'name' and 'address' fields
10 subject = subject, -- subject of e-mail
11 multipart = multipart_type, -- "alternative", "mixed", "related", or nil
12 content_type = content_type, -- only for multipart == nil, defaults to "text/plain"
13 binary = binary, -- allow full 8-bit content
14 content = content or { -- content as lua-string, or table in case of multipart
15 {
16 multipart = multipart_type,
17 ...,
18 content = content or {
19 {...}, ...
20 }
21 }, {
22 ...
23 },
24 ...
25 }
26 }
28 This function sends a mail using the /usr/sbin/sendmail command.
30 --]]--
32 function net.send_mail(args)
33 local mail
34 if type(args) == "string" then
35 mail = args
36 else
37 mail = encode.mime.mail(args)
38 end
39 local envelope_from = args.envelope_from
40 local command
41 if
42 envelope_from and
43 string.find(envelope_from, "^[0-9A-Za-z%.-_@0-9A-Za-z%.-_]+$")
44 then
45 command =
46 "/usr/sbin/sendmail -t -i -f " ..
47 envelope_from ..
48 " > /dev/null 2> /dev/null"
49 else
50 command = "/usr/sbin/sendmail -t -i > /dev/null 2> /dev/null"
51 end
52 trace.debug(command)
53 -- TODO: use pfilter
54 local sendmail = assert(io.popen(command, "w"))
55 sendmail:write(mail)
56 sendmail:close()
57 end

Impressum / About Us