标签:mime smtplib print string pre coding message 一个 utf-8
使用python语言发送邮件smtp,详细见下面脚本#!/usr/bin/python
# -*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.header import Header
# 第三方SMTP服务
mail_host = ‘smtp.126.com‘
mail_user = ‘weiruoyu@126.com‘
mail_pass = ‘12345678‘
sender = ‘weiruoyu@126.com‘
receivers = [‘888888@qq.com‘]
# 三个参数: 第一个为文本内容,第二个plain设置文本格式 ,第三个utf-8设置编码
message = MIMEText(‘Python 邮件发送测试5。。。‘, ‘plain‘, ‘utf-8‘)
message[‘From‘] = ‘weirruoyu@126.com‘ #发送者
message[‘To‘] = ‘888888@qq.com‘ #接收者
subject = ‘Python 测试邮件5‘
message[‘Subject‘] = Header(subject, ‘utf-8‘)
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25)
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print "邮件发送成功"
注意上面的接收者可以随便填写,可以是数字字符
同时126邮箱要在设置里开通 邮箱授权密码
标签:mime smtplib print string pre coding message 一个 utf-8
原文地址:https://blog.51cto.com/weiruoyu/2379506