使用 python 发送邮件

1.使用python 写发邮箱代码:

def sendmail ():
    import smtplib
    from email.mime.text import MIMEText
    from email.utils import formataddr
    msg = MIMEText('邮件内容', 'plain', 'utf-8')
    msg['From'] = formataddr(["发件人名", '发件人地址'])
    msg['Subject'] = "主题"

    server = smtplib.SMTP("发件人邮箱SMTP地址", 25)
    server.login("发件人邮箱地址", "发件人邮箱登录密码")
    server.sendmail('发件人地址', ['送件人地址', ], msg.as_string())
    server.quit()
sendmail()
posted @ 2016-07-03 21:22  Yee.Liu  阅读(291)  评论(0编辑  收藏  举报