webmcp

view framework/env/net/send_mail.lua @ 444:5d307886bd89

Added net.configure_mail{...} function to allow other mail interfaces than sendmail
author jbe
date Sun Feb 28 19:16:03 2016 +0100 (2016-02-28)
parents a54cc7dcabf1
children b7596f5158d4
line source
1 --[[--
2 success = -- true, if mail has been sent successfully, otherwise false
3 net.send_mail{
4 envelope_from = envelope_from, -- envelope from address, not part of mail headers
5 from = from, -- From header address or table with 'name' and 'address' fields
6 sender = sender, -- Sender header address or table with 'name' and 'address' fields
7 reply_to = reply_to, -- Reply-To header address or table with 'name' and 'address' fields
8 to = to, -- To header address or table with 'name' and 'address' fields
9 cc = cc, -- Cc header address or table with 'name' and 'address' fields
10 bcc = bcc, -- Bcc header address or table with 'name' and 'address' fields
11 subject = subject, -- subject of e-mail
12 multipart = multipart_type, -- "alternative", "mixed", "related", or nil
13 content_type = content_type, -- only for multipart == nil, defaults to "text/plain"
14 binary = binary, -- allow full 8-bit content
15 content = content or { -- content as lua-string, or table in case of multipart
16 {
17 multipart = multipart_type,
18 ...,
19 content = content or {
20 {...}, ...
21 }
22 }, {
23 ...
24 },
25 ...
26 }
27 }
29 This function sends a mail using the /usr/sbin/sendmail command. It returns true on success, otherwise false.
31 --]]--
33 function net.send_mail(args)
34 local mail
35 if type(args) == "string" then
36 mail = args
37 else
38 mail = encode.mime.mail(args)
39 end
40 local envelope_from = args.envelope_from
41 local command = table.new(net._mail_config.command)
42 if
43 envelope_from and
44 net._mail_config.envelope_from_option and
45 string.find(envelope_from, "^[0-9A-Za-z%.-_@0-9A-Za-z%.-_]+$")
46 then
47 command[#command+1] = net._mail_config.envelope_from_option
48 command[#command+1] = envelope_from
49 end
50 local stdout, errmsg, status = extos.pfilter(mail, table.unpack(command))
51 if not status then
52 error("Error while calling sendmail: " .. errmsg)
53 end
54 if status == 0 then
55 return true
56 else
57 return false
58 end
59 end

Impressum / About Us