python code to send mail

“”"

Apply for 126 or 163 mailbox

Open service + authorization code

Send by code
"""

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

Message content
msg = MIMEText(content sent,'plain','utf-8')
msg['From'] = formataddr([my name, email sender address])
msg['To'] = formataddr ([Partner's name, mail recipient address])
msg['Subject'] = Subject

server = smtplib.SMTP_SSL (specify the connected mailbox server, specify the port number to connect to the server, the default is 25)
server.login(: login mailbox user name, authorization code) # authorization code
server.sendmail (mail sender address, [ Mail recipient address, ], msg.as_string())
server.quit()

Guess you like

Origin blog.csdn.net/shiguanggege/article/details/113791356