-->
Page 1 of 1

sending email via esp8266 lolin new notemcu v3

PostPosted: Sat Dec 19, 2015 2:37 pm
by amitoha23
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

Re: sending email via esp8266 lolin new notemcu v3

PostPosted: Mon Dec 21, 2015 12:17 am
by Mmiscool
I don't think you will be able to make use of gmail for an smtp server.

A service like smtptogo would probably work better.


I found the following lua example.
https://github.com/nodemcu/nodemcu-firm ... l_smtp.lua


Also found this for arduino.
viewtopic.php?f=8&t=2015


for basic
viewtopic.php?f=43&t=6615&p=34342&hilit=smtp#p34342