How to send an email with Gmail as provider using Python?

后端 未结 14 1675
感情败类
感情败类 2020-11-22 03:29

I am trying to send email (Gmail) using python, but I am getting following error.

Traceback (most recent call last):  
File \"emailSend.py\", line 14, in <         


        
14条回答
  •  渐次进展
    2020-11-22 03:52

        import smtplib
    
        fromadd='from@gmail.com'
        toadd='send@gmail.com'
    
        msg='''hi,how r u'''
        username='abc@gmail.com'
        passwd='password'
    
        try:
            server = smtplib.SMTP('smtp.gmail.com:587')
            server.ehlo()
            server.starttls()
            server.login(username,passwd)
    
            server.sendmail(fromadd,toadd,msg)
            print("Mail Send Successfully")
            server.quit()
    
       except:
            print("Error:unable to send mail")
    
       NOTE:https://www.google.com/settings/security/lesssecureapps that                                                         should be enabled
    

提交回复
热议问题