wallville
Posts: 3
Joined: Mon Jul 28, 2014 4:58 pm

Re: SMTP Mail Server Help

Fri Jun 16, 2017 1:34 am

I want to make sure that none of you think I'm a great programmer. I'm not.

I found this on a site and am cutting and pasting it here...because it worked.

Code: Select all

import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("youremailusername", "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
This is how it played out in my code for a kiosk project I'm doing...that requires physical vibration security and email...to keep peoples hands off the RPi3.

Code: Select all

if vibes <= 3.0:
                    to = 'ManOnTheMoon@someplace.com'
                    gmail_user = 'SomeUserName@gmail.com'
                    gmail_pwd = 'SomeUsersPassword'
                    smtpserver = smtplib.SMTP("smtp.gmail.com",587)
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    smtpserver.ehlo
                    smtpserver.login(gmail_user, gmail_pwd)
                    
                    header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:RPi3 Alert \n'
                    msg = header + '\n My Device has a Physical Security Alert \n\n'
                    smtpserver.sendmail(gmail_user, to, msg)
                    smtpserver.close()
                    print ('sent email')
Notice the order of the handshake with GMail:

Code: Select all

smtpserver = smtplib.SMTP("smtp.gmail.com",587)
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    smtpserver.ehlo
                    smtpserver.login(gmail_user, gmail_pwd)

beaglepi
Posts: 1
Joined: Thu Feb 15, 2018 3:35 pm

Re: SMTP Mail Server Help

Thu Feb 15, 2018 3:44 pm

I had a similar issue with:

mail: cannot send message: Process exited with a non-zero status

I had enabled less secure apps in Gmail, but still,l I got the error.
I fixed it by disabling and reenabling less secure apps.

https://www.google.com/settings/security/lesssecureapps

Return to “Networking and servers”

Who is online

Users browsing this forum: No registered users and 12 guests