-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailWIP.lua
53 lines (51 loc) · 1.28 KB
/
emailWIP.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require("net.identity")
net:registerModule("email",{1,0,0})
smtp = require 'socket.smtp'
ssl = require 'ssl'
function net.email.init(from,user,pass)
net.OnServerCreated:connect(function(s)
s.from=from
s.user=user
s.pass=pass
function s:sendMessage(subject, body, dTable)
local msg = {
headers = {
from = '<'..dTable.email..'>'
to = dTable.nick..' <'..dTable.email..'>',
subject = subject
},
body = body
}
local ok, err = smtp.send {
from = '<'..self.from..'>',
rcpt = '<'..dTable.email..'>',
source = smtp.message(msg),
user = self.user,
password = self.pass,
server = 'smtp.gmail.com',
port = 465,
create = net.sslCreate
}
if not ok then
print("Mail send failed", err) -- better error handling required
end
end
end)
end
function net.sslCreate()
local sock = socket.tcp()
return setmetatable({
connect = function(_, host, port)
local r, e = sock:connect(host, port)
if not r then return r, e end
sock = ssl.wrap(sock, {mode='client', protocol='tlsv1'})
return sock:dohandshake()
end
}, {
__index = function(t,n)
return function(_, ...)
return sock[n](sock, ...)
end
end
})
end