用Python发送邮件

文件:send.py

# -*- coding:utf-8 -*-
#
## 任兴测试用Python发送邮件 import os
import sys
import getopt
import time
import datetime
import string
import os
import datetime
import urllib
import md5 from decimal import * import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
import email #to 收件人邮箱,多个用逗号分隔
def send_mail(title,info,to):
s = smtplib.SMTP_SSL("smtp.exmail.qq.com") username = "abcd@qq.com" #发送邮件的邮箱账号
password = "" #发送邮件的邮箱密码 msg = MIMEMultipart()
msg["Subject"] = title
msg["From"] = username
msg['To'] = ";".join(to)
text_msg = email.MIMEText.MIMEText(info,"html","utf-8") msg.attach(text_msg) s.login(username,password)
s.sendmail(username,to,msg.as_string())
s.close() if __name__ == '__main__':
send_mail("this is title","hello,sir,this is body...",["123@qq.com","456@qq.com"])

运行方式: python send.py

上一篇:python 发送邮件例子


下一篇:利用python发送邮件