惜风不起、唯有努力!
python发送邮件

python发送邮件

源代码

#!/usr/bin/python
#coding:utf8

from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSL
import sys

smtpaddr = 'smtp.qq.com' 
myemail='xxxxxxx@qq.com'
password='xxxxxxxx'
recvmail =sys.argv[1]
subject=sys.argv[2]
content=sys.argv[3]

msg = MIMEText("""%s"""%(content), "plain", "utf-8")
msg['Subject'] = Header(subject, 'utf-8').encode()
msg['From'] = myemail
msg['To'] = recvmail
try:
	smtp = SMTP_SSL( smtpaddr )
	smtp.login(myemail,password)
	smtp.sendmail(myemail,recvmail.split(","),msg.as_string()) 	
	smtp.quit()
	print("success")
except Exception as e:
	print("fail:"+str(e))

发表回复

您的电子邮箱地址不会被公开。