Python sends a message applet

Source: Internet
Author: User

#!/usr/bin/env python# import smtplib for the actual sending  functionimport sysimport getoptimport smtplibsender =  ' [email protected] '        #这里输入发件人邮箱地址 # if there are more than one receiver,  you need to ganerate a list. receiver = [' [email protected] ', ' [email protected] ']   #这里输入收件人地址   cc_receiver = [' [email protected] ' ]     #这里输入抄送地址   server =  ' smtp.163.com '    # Mail server send address port =  '      #端口pwd  =  ' xxxx '    # Your email password commaspace =  ',  ' # import the email modules we ' Ll need#from  email.mime.text import mimetextfrom email. Mimetext import mimetextfrom email. Header import headerdef usaGE ():    usagestr =  ' usage: sendemail -s  "subject"  -c   "Mail_content"     print usagestrdef main (argv):     # get the email content in the  "-C"  argv    try:         opts, args = getopt.getopt (argv,  "S:C:")     except getopt. Getopterror:        usage ()          sys.exit (2)     subject =  "    content = "     for opt, arg in opts:         if opt ==  '-C ':             Content = arg        if opt ==&nbSP; ' -S ':            subject = arg     print content    msg = mimetext (content)          msg[' Subject '] = subject    msg[' from ']  = sender    msg[' to '] = commaspace.join (receiver)      msg[' Cc '] = commaspace.join (cc_receiver)         s  = smtplib. SMTP (Server, port)     s.ehlo ()     s.login (SENDER, PWD)      s.sendmail (Sender, receiver, msg.as_string ())     s.sendmail ( Sender, cc_receiver, msg.as_string ())     s.quit () if __name__== "__main__":     main (sys.argv[1:])

Send Message usage:

Python sendmail.py-s "header"-C "content sent"

This article is from the "Chocolee" blog, make sure to keep this source http://chocolee.blog.51cto.com/8158455/1562520

Python sends a message applet

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.