-->
Page 3 of 6

Re: Send email alert

PostPosted: Mon Jan 19, 2015 10:48 am
by Erni
Using @lightbulb's example here
viewtopic.php?f=19&t=1157&start=10

I made a script for a mail sender with a smtp server that require login authentication (in my case smtpcporp )
The password and username should be Base64 encoded :
https://www.base64encode.org/

Code: Select allconn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)
    print(payload)
    end)

conn:on("disconnection", function(conn,payload)
     print("disconnect")
     conn:close()
end)

conn:on("connection", function(conn,payload)
print("sending...")
conn:send("EHLO smtpcorp.com\r\n");
conn:send("AUTH LOGIN\r\n");
conn:send("aaaaaaaaaaaaaaaaaaaaa==\r\n");--username
conn:send("aaaaaaaaaaaaaaaa\r\n"); --password
conn:send("HELO smtpcorp.com\r\n")
conn:send("MAIL FROM: you@yourmail\r\n");
conn:send("RCPT TO:you@yourmail\r\n");
conn:send("DATA\r\n");
conn:send("From: Esp8266<you@yourmail>\r\n");
conn:send("To: you@yourmai\r\n");
conn:send("Subject: Mail from esp8266\r\n");
conn:send("\r\n");
conn:send("\r\n Here is the body of the mail");
conn:send(".\r\n");
conn:send(".\r\n");

end)

conn:dns('smtpcorp.com',function(conn,ip) ipaddr=ip;
     print(ipaddr)
     conn:connect(2525,ipaddr)
     end)

Re: Send email alert

PostPosted: Mon Jan 19, 2015 3:59 pm
by oskar
Thought that I could change the script(s) to go with gmail but canĀ“t get it to work.
By manually inputing the command sequence in the interpreter i can connect and send email through gmail smtp but not with any of the scripts in this thread.
The module just restart as soon as connection is made.
Posting the smaller example below.
Could maybe someone give me some pointers on how to debug this, could it be that the SSL connection extinguish the heap?

Code: Select allfunction gmail()
   username = "base64username"
   password = "base64pwd"
   from="from@gmail.com"
   to="to@gmail.com"
   
   
   conn=net.createConnection(net.TCP, 1)
   conn:on("receive", function(conn, payload)
       print(payload)
       end)
   
   conn:on("disconnection", function(conn,payload)
        print("disconnect")
        conn:close()
   end)
   
   conn:on("connection", function(conn,payload)
   print("sending...")
   conn:send("EHLO\r\n");
   conn:send("AUTH LOGIN\r\n");
   conn:send(username.."\r\n");--username
   conn:send(password.."\r\n"); --password
   conn:send("MAIL FROM:<" .. from ..">\r\n");
   conn:send("RCPT TO:<" .. to .. ">\r\n");
   conn:send("DATA\r\n");
   conn:send("Subject:%s\r\n%s\r\n.",subject,body);
   conn:send("quit\r\n");
   
   end)
   
   conn:connect(465,"64.233.164.108")
   end)
end


for reference the following sequence works just fine when entered directly into the interpreter.
Code: Select all> conn=net.createConnection(net.TCP, 1)
> conn:on("receive", function(conn, payload)        print(payload)          end)
> conn:connect(465,"64.233.164.108")
> 220 mx.google.com ESMTP t19sm1810904laz.13 - gsmtp

conn:send("EHLO\r\n");
> 250-mx.google.com at your service, [xx.xx.xx.xx]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8

Re: Send email alert

PostPosted: Mon Jan 19, 2015 8:14 pm
by gwizz
Hey - this rocks! You guys/galls seem to have made a great feature already.

I'd like to add my +1 to the ability to add an attachment, and could difficulties with gmail be timing related?

Delays can be added without blocking network, using tmr.alarm(blah, blah, blah) :)

Re: Send email alert

PostPosted: Sat Jan 24, 2015 1:26 pm
by mct75
+1 on SMTP not working unless it's done via the console. I'm using a local relay so no auth problems. Manually banging out conn:send("HELO local.domain.name\r\n") etc works fine.

I think non-blocking delays are the solution, but I can't get any tmr.alarm() to work.