Send a message using Python

Source: Internet
Author: User

Recently need to do a function, count the number of bugs, and then email to the designated person, all the first to understand the use of Python to send mail

The code is as follows:

#coding: Utf-8
Import Smtplib
From email. Mimetext Import Mimetext
From email. Header Import Header

sender = ' [email protected] '         #发件人
receiver = [' [email protected] ', ' [email protected] ']   #收件人 (if only one recipient can write directly: receiver = ' [email protected] ')
Span style= "font-family: Song body; Color: #3366ff; " >smtpserver = ' smtps.zhaopin.com.cn '   #发送邮件服务器
username = ' [email protected] ' #发送邮件服务器的登录用户名  
password = ' user_1223 '   #发送邮件服务器的密码

msg = Mimetext (' #邮件内容
msg[' to ']= ', '. Join (receiver) #邮件内容显示的接收人 (if only one recipient can write directly: msg[' to ']=receiver, Of course, you can also directly replace receiver with the sender name you want to display.
msg[' from ']=sender #邮件内容显示的发件人
msg[' date ']= ' 2014-8-14 ' #邮件内容显示的发送时间
msg[' subject ']=u ' mail subject content ' #邮件的主题

SMTP = Smtplib. SMTP ()
smtp.connect (host= ' 192.168.11.8 ', port=25) #连接邮件服务器
smtp.login (username, password) #登录
Smtp.sendmail (sender, receiver, msg.as_string ()) #发送邮件

Smtp.quit ()

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.