Python automated operation and maintenance Smtplib

Source: Internet
Author: User


1. Implement the message sending function


2. Basic use

import smtplib     # #导入模块import  stringHOST =  "smtp.163.com"      # #定义远程smtp主机SUBJECT  =  " test"          # #定义发送主题TO  =  "[email protected]"         # #定义接收主机FROM  =  "[email protected]"    # #定义发送主机text  =  "python"          ##    # #定义邮件内容BODY  = string.join (          # #定义发送格式内容      "from: %s"  %FROM,      "to : %s"  %TO,     "subject: %s "  %subject,      "",    text    ), "\ r \ n") server =  Smtplib. SMTP ()     # #实例化server. Connect (HOST, "     ##") Connect remote host SERVER.STARTTLS ()           # #启用TLS (Secure transport) mode Server.login ("[email protected]", "ws128711 ")    # #校验远程主机server. SendMail (from,[to],body)       # #邮件发送功能 [sender, Recipient, Content]server.quit ()

# # 550 error occurs when opening the mailbox client authorization code

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/08/3A/wKiom1neOAWiCToxAAPAa2q7ctc700.png "title=" Screenshot from 2017-10-11 15-43-00.png "alt=" Wkiom1neoawictoxaapaa2q7ctc700.png "/>



Test

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/08/3A/wKiom1neODLAc0gZAASBf5ahbek528.png "title=" Screenshot from 2017-10-11 09-10-28.png "alt=" Wkiom1neodlac0gzaasbf5ahbek528.png "/>


3. Personalized Mail

MIME class : It is an Internet standard that expands the e-mail standard to enable it to support non-ASCII word literals, non-text format attachments (binary, sound, image, etc.), consisting of a multipart (multiple parts) message body, Header information that contains non-ASCII characters.

Example: sending an HTML file

import smtplibfrom email.mime.text import mimetext    ## Import Mimetext class import stringhost =  "smtp.163.com" subject =  " TEST" TO =  "[ Email protected] "from = " [email protected] "Msg = mimetext (" ""                 # #创建MIME对象, make HTML content, type, character encoding, etc. 

Test


650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/08/3A/wKiom1neOiiSNI2kAASqgHv7xeQ770.png "title=" Screenshot from 2017-10-11 09-33-46.png "alt=" Wkiom1neoiisni2kaasqghv7xeq770.png "/>

Python automated operation and maintenance Smtplib

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.