Python Email, [Errno 10061] No connection could be made because the target machine actively refused it

后端 未结 2 592
予麋鹿
予麋鹿 2020-12-11 09:59

I want to send a mail in using python, below is my code, but I got the error 10061 at the end, hope anyone can help me, thanks!

import smtplib
fromaddr = \'X         


        
2条回答
  •  生来不讨喜
    2020-12-11 10:42

    As far as I know Gmail and other companies have security to prevent emails being sent from unknown sources, but this link can turn that kind of security off.

    There you can modify the account so it will accept the email.

    I use this code to send email:

    import smtplib
    
    from email.mime.multipart import MIMEMultipart
    
    from email.mime.text import MIMEText
    
    from_address = 'johndoe@gmail.com'
    
    to_address = 'johndoe@gmail.com'
    
    message = MIMEMultipart('Foobar')
    
    epos_liggaam['Subject'] = 'Foobar'
    
    message['From'] = from_address
    
    message['To'] = to_address
    
    content = MIMEText('Some message content', 'plain')
    
    message.attach(content)
    
    mail = smtplib.SMTP('smtp.gmail.com', 587)
    
    mail.ehlo()
    
    mail.starttls()
    
    mail.login(from_address, 'password')
    
    mail.sendmail(from_address,to_address, message.as_string())
    
    mail.close()
    

提交回复
热议问题