Python Send mail

Source: Internet
Author: User

http://blog.csdn.net/lucahan/article/details/52070944

#! /usr/bin/env python #-*-coding:utf-8-*-import smtplib from email.mime.text import mimetext mailto_list=[' [EMAIL&N                           Bsp;protected] #收件人 (list) mail_host= "smtp.163.com" #使用的邮箱的smtp服务器地址, here is the SMTP address of 163 mail_user= "XXX"                     #用户名 mail_pass= "XXX" #密码 mail_postfix= "163.com"  #邮箱的后缀, NetEase is 163.com def send_mail (to_list,sub,content): me= "Hello" + "<" +mail_user+ "@" +mail_postfix+ ">" msg = Mimetext (content,_subtype= ' plain ') msg[' Subject '] = Sub msg[' from ' = Me msg[' to '] = ";". Join (to_list) #将收件人列表以 '; ' Separates try:server = Smtplib.               SMTP () server.connect (mail_host) #连接服务器 Server.login (Mail_user,mail_pass)      #登录操作 Server.sendmail (Me, To_list, msg.as_string ()) Server.close () return True Except Exception, E:print str (e) return False for I in rangE (1): #发送1封, the list above is a few people, this will fill in a few if Send_mail (mailto_list, "phone", "phone is xxx"): #邮件主题和邮件内容      #这是最好写点中文, if you write casually, may be netease as spam message back print "done!"   Else:print "failed!"

  

Python Send mail

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.