Python sends html emails
Import smtplib from email. mime. text import MIMEText mailto_list = ["xxx@xx.com"] mail_host = "smtp.xxx.com" # Set server mail_user = "xxx" # username mail_pass = "xxx" # password mail_postfix = "xxx.com" # sender's suffix def send_mail (to_list, sub, content): # to_list: recipient; sub: topic; content: mail content me = "hello" + "<" + mail_user + "@" + mail_postfix + ">" # Here, hello can be set at will. After receiving the mail, msg = MIMEText (content, _ subtype = 'html', _ charset = 'gb2312 ') # create an instance according to the settings, here, the message msg ['subobject'] = sub # sets the topic msg ['from'] = me msg ['to'] = ";". join (to_list) s = smtplib. SMTP () s. connect (mail_host) # connect to the smtp server s. login (mail_user, mail_pass) # log on to the server s. sendmail (me, to_list, msg. as_string () # Send email s. close () return; send_mail (mailto_list, "hello", "hello xxx ")