PHP
·
发表于 5年以前
·
阅读量:8296
import smtplib
import sys
_user = "xxxxx@xxxx.cn"
_pwd = "xxxxxx"
# jpg类型附件
part = MIMEApplication(open('foo.jpg', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename="foo.jpg")
msg.attach(part)
# pdf类型附件
part = MIMEApplication(open('foo.pdf', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename="foo.pdf")
msg.attach(part)
# mp3类型附件
part = MIMEApplication(open('foo.mp3', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename="foo.mp3")
msg.attach(part)
def sendEmail(sender, receiver, msg):
s = smtplib.SMTP("smtp.ym.163.com", 25, timeout=30) # 连接smtp邮件服务器,端口默认是25
s.login(_user, _pwd) # 登陆服务器
s.sendmail(sender, receiver, msg.as_string()) # 发送邮件
s.close()