The following example is QQ mailbox to QQ mailbox, do not know what other mailboxes are different
(1) First the sender's SMTP service needs to be opened, now send the time required authorization code
Click the Generate authorization code, may want some authentication information, through can see authorization code, copy down
(2) Writing code
#-*-Coding:utf-8-*-
from email.mime.text import mimetext
from Email.header Import Header
# The first is text content, The second format text, the third encoded format
msg = mimetext (' python Mail send Test ', ' plain ', ' utf-8 ')
# appears on sender
msg[' from '] = Header (' I am sender ', ' Utf-8 ')
# display with recipient
msg[' to '] = header (' Yourself ', ' Utf-8 ')
# is the title, most eye-catching
subject = ' Python smtp send mail Test _9.20 '
msg[' Subject '] = Header (Subject, ' Utf-8 ')
#
send side
from_addr = ' sender @qq.com '
# must be an automatic authorization code, Need to send person's authorization code
password = ' abcdefghijklmn '
# QQ SMTP server
smtp_server = ' smtp.qq.com '
# receiver
To_ Addr = ' recipient @qq.com '
import smtplib
# server = Smtplib. SMTP (smtp_server,25)
# uses the SSL mode
server = Smtplib. Smtp_ssl (smtp_server,465)
# set to debug mode
server.set_debuglevel (1)
# login SSL server
server.login (from_ Addr,password)
# Send mail
server.sendmail (from_addr,[to_addr],msg.as_string ())
# exit
Server.quit ( )
(3) Successful delivery