python3使用smtplib发电子邮件

        smtplib模块smtp简单邮件传输协议client实现。对于多功能性,有时,当你要发送带附件的邮件或图片,使用email.mime加载内容。

码,如以下:

import smtplib
import email.mime.multipart
import email.mime.text

msg=email.mime.multipart.MIMEMultipart()
msg['from']='ustchacker@tom.com'
msg['to']='blablabla@aliyun.com'
msg['subject']='test'
content='''
	你好,
	        这是一封自己主动发送的邮件。

www.ustchacker.com ''' txt=email.mime.text.MIMEText(content) msg.attach(txt) smtp=smtplib smtp=smtplib.SMTP() smtp.connect('smtp.tom.com','25') smtp.login('ustchacker@tom.com','password') smtp.sendmail('ustchacker@tom.com','blablabla@aliyun.com',str(msg)) smtp.quit()


查看邮箱内容:


        能够看到,用Python发送邮件仅仅须要用smtplib的connect(连接到邮件server)、login(登陆验证)、sendmail(发送邮件)三个步骤就可以,简单方便。


转载请注明:转自http://blog.csdn.net/littlethunder/article/details/29355403

版权声明:本文博客原创文章。博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/zfyouxi/p/4732712.html