import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

my_sender = '[email protected]'  # Sender email account
my_pass = 'xxxxxx'  Sender email password
my_user = '[email protected]'  # Recipient email account, I send it to myself
msg = MIMEText('I like you so much.'.'plain'.'utf-8')
msg['From'] = formataddr(["FromTask", my_sender])  The corresponding sender's email nickname and sender's email account in parentheses
msg['To'] = formataddr(["Crawler", my_user])  # The recipient's email nickname and recipient's email account in parentheses
msg['Subject'] = "miss you"  # The subject of the email

server = smtplib.SMTP_SSL("smtp.163.com", 465).# SMTP server in sender's mailbox
server.login(my_sender, my_pass)  # Parentheses correspond to the sender email account and password
server.sendmail(my_sender, [my_user, ], msg.as_string())  # Parentheses correspond to the sender email account, recipient email account, and send email
server.quit()  # close the connection
Copy the code