Question

I am fairly new to python so I need lots of help with stuff :) I am having issues with this:

elif(command == "email" or command == "Email"):
    server = smtplib.SMTP('smtp.gmail.com', 587)
    euser = input("Enter Gmail Username: ")
    epass = input("Enter Gmail Password: ")
    server.login(euser, epass)
    msginput = input("Enter Message: ")
    msg = ("\n"+msginput)
    sourcemail = input("Enter Your Email: ")
    targetemail = input("Enter Your Recipient: ")
    server.sendmail(sourcemail, targetemail, msg)

All of this may be wrong. However, after I enter my gmail username and password, it gives this:

Traceback (most recent call last):
  File "/Users/19austinh/Google Drive/Other/Python/Login.py", line 145, in <module>
    server.login(euser, epass)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/smtplib.py", line 595, in login
    raise SMTPException("SMTP AUTH extension not supported by server.")
smtplib.SMTPException: SMTP AUTH extension not supported by server.

I don't know how to fix that. Also, is my script correct? If not, please tell me what to fix. Any answers are greatly appreciated :)

Edit:

Also, how do you make a subject input? So do I just add:

subjectinput = input("Enter Subject: ") 

and

smtplib.subject = ("\n"+subjectinput)

or something? Because it does not send the email when I did that.

Was it helpful?

Solution

According to Gmail APIs documentation:

The outgoing SMTP server, smtp.gmail.com, requires TLS. Use port 465, or port 587 if your client begins with plain text before issuing the STARTTLS command.

Call starttls before login:

smtp = smtplib.SMTP('smtp.gmail.com', 587)
smtp.starttls() # <---------
smtp.login(username, password)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top