python python发送电子邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python python发送电子邮件相关的知识,希望对你有一定的参考价值。

import smtplib


smtpObj = smtplib.SMTP('smtp.gmail.com', 587)  # Create SMTP object
smtpObj.ehlo()  # Sending the hello message, If the first number return is 250, the connection succeeded
smtpObj.starttls()  # For port 587, there is a need to start tls connection, for port 445 (ssl) we can skip this step, if the return value is 220 the server is ready.
password = raw_input('Please enter your passowrd: ')
smtpObj.login('test@gmail.com', password)  # The user name and password
smtpObj.sendmail('test@gmail.com', 'test@gmail.com', 'Subject: How are you?\nLong time no see')  # Sender, receiver and subject, return value 235 means that the connection went well.
# If the 'sendmail' function failed, it will return dictionary of each recipient that the email fail to send the email, empty dictionary = success.
smtpObj.quit()  # Close the connection, the 221 return value means tha the connection is ending.
print ('Email sent :)')

以上是关于python python发送电子邮件的主要内容,如果未能解决你的问题,请参考以下文章

python 发送邮件,附件中文命名,怎么破

python发送邮件(转)

Python 发送邮件

如何用python通过163发送邮件

python 发送邮件

python发送邮件