sending email via esp8266 lolin new notemcu v3
Posted: Sat Dec 19, 2015 2:37 pm
Hello ,
i am new in this forum so i am sorry for asking questions already been asked , my project is to connect the esp to my alarm system to send email/sms to my phone .
is been discussed in this forum but i have been trying to find like simple code for newbie but all seems to be not ready to run but needed basic knowledge in lua which i dont have , i found this code :
local socket = require 'socket'
local smtp = require 'socket.smtp'
local ssl = require 'ssl'
local https = require 'ssl.https'
local ltn12 = require 'ltn12'
function 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
function sendMessage(subject, body)
local msg = {
headers = {
to = 'xxxxx@xxxx.xxxx>',
subject = subject
},
body = body
}
local ok, err = smtp.send {
from = '<xxxxxxx@gmail.com>',
rcpt = '<xxxx@xxx.xxxl>',
source = smtp.message(msg),
user = 'xxxxxxxxx@gmail.com',
password = 'xxxxxxxx',
server = 'smtp.gmail.com',
port = 465,
create = sslCreate
}
if not ok then
print("Mail send failed", err) -- better error handling required
end
end
it should work for sending emails via gmail , but it need some libraries like " socket " and smtp ...
can some one please point me to where to gets this libraries , and how to install them .
and if some one can tell me if this code will work or help me with my code.
the basic concept is simple . the alarm will pull up/down a gpio pin ,then the esp will send email .
thank you all for your help
Amit
i am new in this forum so i am sorry for asking questions already been asked , my project is to connect the esp to my alarm system to send email/sms to my phone .
is been discussed in this forum but i have been trying to find like simple code for newbie but all seems to be not ready to run but needed basic knowledge in lua which i dont have , i found this code :
local socket = require 'socket'
local smtp = require 'socket.smtp'
local ssl = require 'ssl'
local https = require 'ssl.https'
local ltn12 = require 'ltn12'
function 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
function sendMessage(subject, body)
local msg = {
headers = {
to = 'xxxxx@xxxx.xxxx>',
subject = subject
},
body = body
}
local ok, err = smtp.send {
from = '<xxxxxxx@gmail.com>',
rcpt = '<xxxx@xxx.xxxl>',
source = smtp.message(msg),
user = 'xxxxxxxxx@gmail.com',
password = 'xxxxxxxx',
server = 'smtp.gmail.com',
port = 465,
create = sslCreate
}
if not ok then
print("Mail send failed", err) -- better error handling required
end
end
it should work for sending emails via gmail , but it need some libraries like " socket " and smtp ...
can some one please point me to where to gets this libraries , and how to install them .
and if some one can tell me if this code will work or help me with my code.
the basic concept is simple . the alarm will pull up/down a gpio pin ,then the esp will send email .
thank you all for your help
Amit