Hello,
I’m looking to send an email from the spark core when triggered by a sensor. I’ve been trying with some code from a topic here called “Sending emails from the core, locking up!”
I’m not having any luck getting it to run.
Can anyone help with some code that successfully sends email out via SMTP? Or direct me to somewhere with some documentation that will help?
I have one that works with arduino, was working on the core but since a couple of days it doesnt work anymore… I was using println command… tired of problems and uneven performance of this thing.
I’m getting close, still working on this, just making the function a little more robust when handling AUTH with some SMTP servers.
edit: This isn’t instant you know!
edit 2: Okay, this is weird, I was having problems with the first SMTP server, so I switched, and this one doesn’t want me to say EHLO, etc. So I’m digging in, not gonna give up!
This is very neat @Dave – it would have never occurred to me to call SPARK_WAN_Loop() directly. I guess the stack will get untangled eventually.
I did notice that authenticate has three 5 second timeouts in a row before a call to idle() so that could still be a problem.
Also just so everybody knows, not all sendmail programs return the exact same codes for all commands. The RFC has a list, but the best thing might be to telnet into your mail service and do the transaction by hand and see what the response codes are. For instance, my mail server replies with a 350 for the AUTH LOGIN and the rest of the text from the service is base64 encoded until you get the username and password in. In general, the 2xx codes mean success and the 3xx codes mean success so far but please go on. The 4xx codes mean please try again and 5xx codes mean error.
Totally, just in the event the socket behavior took longer, I wanted to make sure nothing was blocked for long. You’re absolutely right that SMTP servers won’t return exactly the same codes, that would be a great upgrade to this library.
OK, I must be missing something… I’ve cut and pasted your code into the IDE, but it won’t compile, it gives me the errors below. Maybe I need to open the .cpp file instead of just cut and past of the text? But I can’t figure out how to do that in Spark Build.
So can you point me to somewhere that could help me figure out why I can’t make it work?
Sorry for the Noob-ness!
Thanks!
Jim
the_user_app.cpp:9:22: error: variable or field ‘echoSocketWrite’ declared void
the_user_app.cpp:9:22: error: ‘TCPClient’ was not declared in this scope
the_user_app.cpp:9:37: error: expected primary-expression before 'const’
the_user_app.cpp:10:22: error: variable or field ‘echoSocketWrite’ declared void
the_user_app.cpp:10:22: error: ‘TCPClient’ was not declared in this scope
the_user_app.cpp:10:37: error: ‘String’ was not declared in this scope
the_user_app.cpp:11:20: error: variable or field ‘flushToSerial’ declared void
the_user_app.cpp:11:20: error: ‘TCPClient’ was not declared in this scope
the_user_app.cpp:3:6: error: previous declaration of ‘void setup()’ with ‘C++’ linkage
In file included from …/inc/spark_wiring.h:31:0,
from …/inc/application.h:29,
from the_user_app.cpp:10:
…/inc/spark_utilities.h:116:35: error: conflicts with new declaration with ‘C’ linkage
the_user_app.cpp:4:6: error: previous declaration of ‘void loop()’ with ‘C++’ linkage
In file included from …/inc/spark_wiring.h:31:0,
from …/inc/application.h:29,
from the_user_app.cpp:10:
…/inc/spark_utilities.h:117:34: error: conflicts with new declaration with ‘C’ linkage
the_user_app.cpp: In function ‘void loop()’:
the_user_app.cpp:43:138: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:43:138: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:43:138: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:43:138: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:43:138: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:43:138: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:43:138: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp: In function ‘int SendEmail(char*, char*, char*, char*, char*, char*, char*)’:
the_user_app.cpp:83:101: error: ‘echoSocketWrite’ was not declared in this scope
the_user_app.cpp:85:25: error: ‘flushToSerial’ was not declared in this scope
the_user_app.cpp:101:37: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:107:37: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp: In function ‘int handshake(char*)’:
the_user_app.cpp:120:25: error: ‘flushToSerial’ was not declared in this scope
the_user_app.cpp:122:37: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:129:82: error: ‘echoSocketWrite’ was not declared in this scope
the_user_app.cpp:130:37: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp: In function ‘int authenticate(char*, char*)’:
the_user_app.cpp:142:45: error: ‘echoSocketWrite’ was not declared in this scope
the_user_app.cpp:143:33: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:146:33: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp:149:33: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
the_user_app.cpp: In function ‘void echoSocketWrite(TCPClient, String)’:
the_user_app.cpp:162:19: error: ‘flushToSerial’ was not declared in this scope
the_user_app.cpp: In function ‘int SendEmail(char*, char*, char*, char*, char*, char*, char*)’:
the_user_app.cpp:114:1: warning: control reaches end of non-void function [-Wreturn-type]
make: *** [the_user_app.o] Error 1
Error: Could not compile. Please review your code.
Thanks! It’s a super-rough example. At some point I’ll have to go back and do proper response checking and actually break it into a library and whatnot.
The general TCP functions of “listen for this kind of response” is something I’d like to build a few more of, since I suspect it’ll go a long way to make it way easier to expand on and write more networking libraries like this.
I’m not 1200% sure, but I think calling “SPARK_WLAN_Loop” will also call “Spark_Communication_Loop”, which should handle stuff like responding to flashing, responding to variable / function requests, etc.
So I have had some time to play around tonight, the code works fabulously but I am seeing some strangeness in the serial output. It starts in this section of the code:
Notice the ‘2.7.0 Authen’ prefixing all the commands after it, this continues to happen all the way through to the ‘End Data’ I think.
Still going through stuff, mainly just getting the formatting right in putty so I can diagnose the problem via the output. I suppose it’s only semantic at this point because the emails seem pretty solid.