Python emails and python emails

Source: Internet
Author: User

Python emails and python emails

1 #-*-coding: UTF-8-*-2 ''' 3 Send txt text mail 4 http://www.cnblogs.com/liu-ke 5 ''' 6 import smtplib 7 from email. mime. text import MIMEText 8 mailto_list = ['***@**. * ** '] 9 mail_host = "smtp. ****. com "# Set Server 10 mail_user = "***@**. ** "# username 11 mail_pass =" ********* "# password 12 mail_postfix = "***. com "# The suffix of the sender is 13 14 def send_mail (to_list, sub, content ): 15 me = "hello" + "<" + mail_user + "@" + mail_postfix + ">" 16 msg = MIMEText (c Ontent, _ subtype = 'plain ', _ charset = 'gb2312 ') 17 msg ['subobject'] = sub 18 msg ['from'] = me 19 msg ['to'] = ";". join (to_list) 20 try: 21 server = smtplib. SMTP () 22 server. connect (mail_host) 23 server. login (mail_user, mail_pass) 24 server. sendmail (me, to_list, msg. as_string () 25 server. close () 26 return True 27 failed t Exception, e: 28 print str (e) 29 return False 30 if _ name _ = '_ main __': 31 if send _ Mail (mailto_list, "hello", "hello world! "): 32 print" sent successfully "33 else: 34 print" failed to send"

 

 

1 #-*-coding: UTF-8-*-2 ''' 3 send html text mail 4 http://www.cnblogs.com/liu-ke 5 ''' 6 import smtplib 7 from email. mime. text import MIMEText 8 mailto_list = ["*****"] 9 mail_host = "smtp. ***. com "# Set Server 10 mail_user =" ***** "# username 11 mail_pass =" ***** "# password 12 mail_postfix = "***. com "# The suffix of the sender is 13 14 def send_mail (to_list, sub, content): # to_list: recipient; sub: topic; content: email content 15 me = "hello" + "<" + mail_user + "@" + mail_postfix + ">" # Here, hello can be set as needed. After receiving the email, 16 msg = MIMEText (content, _ subtype = 'html', _ charset = 'gb2312 ') # create an instance according to the settings, here we set the email To html format 17 msg ['subobject'] = sub # Set the topic 18 msg ['from'] = me 19 msg ['to'] = ";". join (to_list) 20 try: 21 s = smtplib. SMTP () 22 s. connect (mail_host) # connect to the smtp server for 23 s. login (mail_user, mail_pass) # log on to the server for 24 s. sendmail (me, to_list, msg. as_string () # Send email for 25 s. close () 26 return True 27 failed t Exception, e: 28 print str (e) 29 return False 30 if _ name _ = '_ main __': 31 if send_mail (mailto_list, "hello", "<a href = 'HTTP: // www.cnblogs.com/xiaowuyi'> Xiao Wuyi </a>"): 32 print "sent successfully ", mailto_list 33 else: 34 print "failed to send"

 

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.