Python supports SMTP support with smtplib and email Two modules,email responsible for structuring the message, Smtplib responsible for sending mail
Import smtplib # send mail module
From Email.mime.text import Mimetext # defining message Content
From Email.header Import Header # defining message Headers
# Send Mailbox Server
Smtpserver= ' smtp.163.com '
# Send mailbox user name password
user= ' [email protected] '
Password= ' ... '
# send and receive mailboxes
sender= ' [email protected] '
receive= ' [email protected] '
# Send message subject and content
subject= ' python send mail '
Content= ' python send mail test !
#HTML message body
msg=mimetext(content, ' html ', ' Utf-8 ')
msg[' Subject ']=Header(Subject, ' utf-8 ')
msg[' from ']=sender
Msg[' to '] = Receive
#SSL protocol port number to use 465
SMTP = Smtplib. Smtp_ssl (SmtpServer, 465)
#HELO identify user identities to the server
Smtp. helo (SmtpServer)
# Server returns result confirmation
Smtp. EHLO (SmtpServer)
# Logon Mailbox Server user name and password
Smtp. Login (User,password)
Print (" start sending mail ... ")
Smtp. SendMail (Sender,receive,msg.as_string ())
Smtp. quit ()
Print (" mail sent is complete!") ")
Python Send mail