#!/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