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

后端 未结 14 1687
感情败类
感情败类 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:51

    Not directly related but still worth pointing out is that my package tries to make sending gmail messages really quick and painless. It also tries to maintain a list of errors and tries to point to the solution immediately.

    It would literally only need this code to do exactly what you wrote:

    import yagmail
    yag = yagmail.SMTP('user_me@gmail.com')
    yag.send('user_you@gmail.com', 'Why,Oh why!')
    

    Or a one liner:

    yagmail.SMTP('user_me@gmail.com').send('user_you@gmail.com', 'Why,Oh why!')
    

    For the package/installation please look at git or pip, available for both Python 2 and 3.

提交回复
热议问题