I will test your code using using system calls from Arduino. In the meantime, why don’t you try adding delays between the server lines? Just to make sure that your code has enough time to perform correctly.
Where should I add a delay? In the python code or the Arduino code? And where exactly? Server client stuff is very new to me,
any results yet? I've tried adding delays in the Arduino sketch to no avail
I’ve running some tests but I’m getting the same behavior. The code runs well if run directly with python, but once you try to call it using system calls in the Arduino IDE nothing happens. I tested your code and some other email code from this GitHub link https://github.com/MakersTeam/Edison/tree/master/Python-Examples/Email, maybe you’d like to take a look.
Regarding your first question about the delays, what I meant was to add delays between server calls, so the code had enough time (if that was the case) to run correctly. But that didn’t solve the issue. I’ll try some other things and I’ll let you know soon.
Here's my updated python script with delays all over the place:
t = open('/home/root/testLog.txt', 'a+')
fromaddr = 'firstname.lastname@example.org'
toaddrs = 'email@example.com'
file = open('message.txt', 'r+').read()
#Uncomment for debugging
username = 'firstname.lastname@example.org'
password = 'heyjude3141'
server = smtplib.SMTP('smtp.gmail.com:587')
server.sendmail(fromaddr, toaddrs, file)
What could be the problem here? Maybe after the system command is executed by the arduino code, the process initiated by that command immediately comes to a halt, unlike when running the command directly on the command line.
Anyways I'm looking for other ways, though i can't find many. Sending mail using Arduino code is the only option. I've downlobaded this library but can't seem to figure out how it works (documentation is poor): gregington/SMTPClient · GitHub Any help with that? And maybe any other arduino code for sending emails via gmail?
Adding delays doesn’t seem to make any difference. We also tried this a week ago.
If you can only use Arduino for this, you can also try with FullIP, another SMTP library for Arduino. It’s similar to SMTPClient. I would suggest you to take a look at this library, in the meantime, we will check the SMTPClient library and will try to help you with that one.
is there a need to run on Arduino? you surely could run an SMTP server ... likewise directly on Linux.
Otherwise you might also consider having a listening process running on Linux which is triggered from Arduino (see e.g. IoT - Efficient communication between Arduino* and Linux native processes | Intel® Developer Zone)