EDIT: The main error is when this script runs from different IP / Wifi or whatever. It will just cancel it like skip over it or whatever.
I'm trying to send an email with text that says something. (or I can insert a variable for example: score = 32
and I would put 'score' in body without the ' '.)
The following code is what I'm using:
import smtplib
gmail_user = 'name@gmail.com'
gmail_password = 'password'
sent_from = gmail_user
to = 'me@gmail.com'
subject = 'OMG Super Important Message'
body = 'blah blah blah this is a message'
email_text = """\
From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(to), subject, body)
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(sent_from, to, email_text)
server.close()
print 'Email sent!'
except:
print 'Something went wrong...'
So where it says 'body' I can put like a variable not just a text and it would send. But now,
when I send a program to someone and they go through the steps until this and the script will just skip it because the print 'loaded successful' one won't print meaning it didn't work. Any help on how to fix?
You'll have to enable less secure apps in order to access your gmail
account via smtplib
.
If an app or device doesn’t meet our security standards, Google will block anyone who tries to sign in from that app or device. Because these apps and devices are easier to break into, blocking them helps keep your account safe.
Some examples of apps that do not support the latest security standards include:
To help keep Google Accounts through work, school, or other groups more secure, we block some less secure apps from using them. If you have this kind of account, you’ll see a "Password incorrect" error when trying to sign in. If so, you have two options:
If you still can't sign in to your account, learn more about the "password incorrect" error.