Python Network Protocol Module Learning Smtplib

Source: Internet
Author: User

function: send e-mail via mail server, Smtplib is an implementation of SMTP client, Support message format: text, HTML, Image, EXCEL

1. Ordinary text mail

#!/usr/bin/env python# coding:utf-8import smtplibimport stringhost =  " Smtp.qq.com "         #定义smtp主机subject  = " Test email  from python "       #定义邮件主题to_mail  = " [email protected] "        #邮件收件人from_email  =  "[email protected]"        #邮件发件人password  =  "Pass"           # Message sender Mailbox Password text =  "hello python!"         #邮件内容body  = string.join (          #组装sendmail方法的邮件主题内容, sections with "\ r \ n" for division          "from:  %s " % from_email,        " to: %s " % to_ mail,         "subject: %s"  % subject,         "",        text         ),  "\ r \ n") server = smtplib. SMTP ()        #创建一个SMTP () object Server.connect (host,  ")      #通过connect方法连接smtp主机server. STARTTLS ()           # Start Secure transfer Mode Server.login (From_email,password)         #邮箱账户登录认证server. SendMail ( From_email,to_mail,body)          #邮件发送server. Quit ()          #断开smtp连接


This article is from the "Penguin" blog, please be sure to keep this source http://lizhenliang.blog.51cto.com/7876557/1636514

Python Network Protocol Module Learning Smtplib

Related Article

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.