I want to send an email by use of Python 3. I cannot yet make sense of the examples that I have seen. Here is one reference: Using Python to Send Email
I have pulled the first simple example found on the above reference. I find this example a good representation of the combination of examples I have seen on the internet. It seems to be the basic form of doing what I am trying to do.
When I try the code below, I receive Error:
File "C:\Python33\Lib\email.py", line 595, in login
raise SMTPException("SMTP AUTH extension not supported by server.")
smtplib.SMTPException: SMTP AUTH extension not supported by server.
Here is the code:
# Send Mail
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
# Log in to the server
server.login("[email protected]","myPassword")
# Send mail
msg = "\nHello!"
server.sendmail("[email protected]","[email protected]", msg)
I have found a solution on YouTube.
Here is the video link.
# smtplib module send mail
import smtplib
TO = '[email protected]'
SUBJECT = 'TEST MAIL'
TEXT = 'Here is a message from python.'
# Gmail Sign In
gmail_sender = '[email protected]'
gmail_passwd = 'password'
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_sender, gmail_passwd)
BODY = '\r\n'.join(['To: %s' % TO,
'From: %s' % gmail_sender,
'Subject: %s' % SUBJECT,
'', TEXT])
try:
server.sendmail(gmail_sender, [TO], BODY)
print ('email sent')
except:
print ('error sending mail')
server.quit()