smtplib模块smtp简单邮件传输协议client实现。对于多功能性,有时,当你要发送带附件的邮件或图片,使用email.mime加载内容。
码,如以下:
import smtplibimport email.mime.multipartimport email.mime.textmsg=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(发送邮件)三个步骤就可以,简单方便。
转载请注明:转自
版权声明:本文博客原创文章。博客,未经同意,不得转载。