python 用Python发送电子邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 用Python发送电子邮件相关的知识,希望对你有一定的参考价值。
#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
username = 'USERNAME'
password = 'PASSWORD'
msg = MIMEMultipart('mixed')
sender = 'sender@example.com'
recipient = 'recipient@example.com'
msg['Subject'] = 'Your Subject'
msg['From'] = sender
msg['To'] = recipient
text_message = MIMEText('It is a text message.', 'plain')
html_message = MIMEText('It is a html message.', 'html')
msg.attach(text_message)
msg.attach(html_message)
mailServer = smtplib.SMTP('mail.smtp2go.com', 2525) # 8025, 587 and 25 can also be used.
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(username, password)
mailServer.sendmail(sender, recipient, msg.as_string())
mailServer.close()
# from: https://www.smtp2go.com/setupguide/python/
以上是关于python 用Python发送电子邮件的主要内容,如果未能解决你的问题,请参考以下文章
用python自动发送邮件详细教程
干货 | 解放双手,用Python实现自动发送邮件
用python 发送一个smtp邮件
python 发送邮件
用python发送电子邮件,消息丢失
我如何让Raspberry Pi用python发送带有图片的电子邮件