Python implementation of simple send mail script sharing _python

Source: Internet
Author: User

Recently some things need to monitor the alarm to send mail, and then find some material on the internet, they wrote a simple email script, mainly using Python's Smtplib module, to share with everyone to see:

Copy Code code as follows:

#!/usr/bin/env python
#-*-Coding:utf-8-*-
#导入smtplib和MIMEText
Import Smtplib,sys
From Email.mime.text import Mimetext

def send_mail (sub,content):
#############
#要发给谁, 1 people here.
mailto_list=["Wangwei03@jb51.net"]
#####################
#设置服务器, username, password, and suffix of the mailbox
Mail_host= "mail.gyyx.cn"
Mail_user= "Wangwei03@jb51.net"
Mail_pass= "123456677890"
mail_postfix= "gyyx.cn"
######################
'''''
To_list: Who is it sent to?
Sub: Theme
Content: Contents
Send_mail ("aaa@126.com", "sub", "Content")
'''
Me=mail_user+ "<" +mail_user+ "@" +mail_postfix+ ">"
msg = Mimetext (content,_charset= ' GBK ')
msg[' Subject ' = Sub
msg[' from ' = Me
Msg[' to '] = ";". Join (Mailto_list)
Try
s = smtplib. SMTP ()
S.connect (Mail_host)
S.login (Mail_user,mail_pass)
S.sendmail (Me, Mailto_list, msg.as_string ())
S.close ()
Return True
Except Exception, E:
Print str (e)
Return False
if __name__ = = ' __main__ ':
If Send_mail (U ' This is the Python test mail ', u ' python Send mail '):
Print u ' send success '
Else
Print u ' send failed '

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.