Python3 e-mail smtplib & Email Library

Source: Internet
Author: User
Tags email account

Hey realized the use of 163 sent to QQ function, left two questions:

1. The recipient list will error;
Update: Because list[] will pass the past a real []list, changed to the following:
Before:
maillist=['[email protected]','[email protected]'] msg[' to']=maillistPrint(maillist)-->['[email protected]','[email protected]'] After:maillist= ['[email protected]','[email protected]'] msg[' to'] =','. Join (maillist)Print(maillist)-[email protected],[email protected]


2. What do you mean by msg.as_string ()?
Update: The MSG is turned into a string


Hit is not want Google Ah hello, feel recently Google more and more can't find the answer you want.
Update: Still have to continue Google down, continue to ask to go on Ah, in addition, the official English document read also do not understand, embarrassed a embarrassed

Paste part of the code to facilitate the lazy copy:

defsendmail (Subject, content): Email_host='smtp.163.com'     #Sender is 163 mailboxEmail_user ='Sender email account, I replace with Chinese characters'  #Sender AccountEmail_pwd ='Sender Email password, I replace it with Chinese characters'       #Sender PasswordMaillist ='Recipient email account, I replace with Chinese characters'    #receiver account, originally wanted to write []list, but error, not solved! me =Email_user#three parameters: the first is the text content, the second HTML formats the text, the third utf-8 sets the encodingmsg = Mimetext (content,'HTML','Utf-8')#Message Contentmsg['Subject'] = subject#Message Subjectmsg[' from'] = Me#Sender Accountmsg[' to'] = Maillist#Recipient Account List (list not implemented)SMTP= Smtplib. SMTP (Email_host)#The variables defined above are 163 mailboxes .Smtp.login (Email_user, Email_pwd)#Sender's email account, passwordSmtp.sendmail (Me, Maillist, msg.as_string ())#The parameters are the sender, the receiver, the third one does not knowSmtp.quit ()#exit SMTP When send is complete    Print('email send success.') SendMail ('Theme','content')#call a function that sends a mailbox

There's a second way to do it, but I like the one above, it's loveisbug, it feels like a program.

The second is from the Internet to find, the author forgot, really forgot, yesterday search

ImportSmtplibImportEmail.mime.multipartImportemail.mime.textmsg=Email.mime.multipart.MIMEMultipart () msg[' from'] ='Sender's email account'msg[' to'] ='Recipient's email account'msg['subject'] ='test, this is the subject of the message'content=" ""Hello, this is the content of an automatically sent message." " "txt=email.mime.text.MIMEText (content) Msg.attach (TXT) SMTP=SMTPLIBSMTP=Smtplib. SMTP () Smtp.connect ('smtp.163.com'# What about the sender's mailbox that was used, Postsmtp.login ('Sender's email account','Sender's Email password') Smtp.sendmail ('Sender's email account','Recipient's email account', str (msg)) Smtp.quit ()

Python3 e-mail smtplib & Email library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.