The smtplib module is the implementation of the smtp Simple Mail transmission protocol client. For the sake of universality, sometimes attachments or images are required to be sent and the content is loaded using email. mime. The Code is as follows:
Import smtplibimport email. mime. multipartimport email. mime. textmsg = email. mime. multipart. MIMEMultipart () msg ['from'] = 'ustchacker @ tom.com 'msg ['to'] = 'blablabla @ aliyun.com' msg ['subobject'] = 'test' content = ''' hello, this is an automatic email. Www.ustchacker.com ''' txt = email. mime. text. MIMEText (content) msg. attach (txt) smtp = smtplibsmtp = smtplib. SMTP () smtp. connect ('smtp .tom.com ', '25') smtp. login ('ustchacker @ tom.com ', 'Password') smtp. sendmail ('maid @ tom.com ', 'blablabla @ aliyun.com', str (msg) smtp. quit ()
View email content:
As you can see, to send emails in Python, you only need to use the connect (connect to the mail server), login (login verification), and sendmail (send mail) steps, which is simple and convenient.
Reprinted Please note: