使用Python发送邮件
#!/usr/local/Python/bin/python3
#description【 python3 mail.py *******@qq.com 主题 内容 】
#coding:utf-8
import smtplib,sys
from email.mime.text import MIMEText
def send_mail(rec_user,subject,content):
smtp_host = ‘smtp.163.com‘
smtp_user = ‘‘
smtp_pass = ‘*******‘
msg = MIMEText(content,_subtype=‘plain‘)
msg[‘Subject‘]=subject
msg[‘From‘] = smtp_user
msg[‘To‘] = rec_user
server = smtplib.SMTP()
server.connect(smtp_host)
#如果使用了加密通信,需要开启下面的选项 默认 25端口,加密默认端口 465
#server.starttls()
server.login(smtp_user,smtp_pass)
server.sendmail(smtp_user,rec_user,msg.as_string())
server.close()
if __name__ == ‘__main__‘:
rec_user = sys.argv[1].strip()
subject = sys.argv[2].strip()
content = sys.argv[3].strip()
try:
send_mail(rec_user,subject,content)
except Exception as e:
print(‘send error: {}.‘.format(e))
else:
print(‘send to {} success!‘.format(rec_user))
相关推荐
一叶不知秋 2020-07-09
Ericbig 2020-05-30
千锋 2020-05-13
Sophisticated 2020-05-09
wklken的笔记 2019-12-25
xiaoxiaoniaoer 2019-12-07
zluxingzhe 2019-12-01
JFEE 2019-04-16
xiaogeldx 2011-09-07
程松 2019-06-30
小方哥哥 2019-06-30
zhongranxu 2019-06-27
idning 2019-04-08
Cowry 2019-03-13
tmaczt 2019-02-20
Dandelionlcp 2019-04-30
huang00 2017-04-26
小海 2018-06-21