美文网首页
python 163邮箱发邮件

python 163邮箱发邮件

作者: 23b813a14221 | 来源:发表于2017-09-28 14:18 被阅读0次

#!/usr/bin/python

# -*- coding: UTF-8 -*-

import os

import copy

import time

import sys

import urllib

import shutil

import smtplib

from email.mime.text import MIMEText

from email.header import Header

sender="xxx@163.com"#“我”的邮箱

password="xxx"#密码

receiver="xxx@xx.com"#接收者邮箱

subject="测试标题"#邮件标题

words="测试正文"#邮件正文

smtpserver='smtp.163.com'

msg=MIMEText(words, 'plain', 'utf-8')#中文需参数‘utf-8',单字节字符不需要

msg['Subject'] = Header(subject, 'utf-8')#邮件标题

msg['from'] = sender#发信人地址

msg['to'] = receiver#收信人地址

smtp=smtplib.SMTP()

smtp.connect('smtp.163.com')

smtp.login(sender, password)

smtp.sendmail(sender, receiver, msg.as_string())#这行代码解决的下方554的错误

smtp.quit()

print"邮件发送成功!"

相关文章

网友评论

      本文标题:python 163邮箱发邮件

      本文链接:https://www.haomeiwen.com/subject/ojnmextx.html