首页 > 代码库 > python 发邮件小程序一枚
python 发邮件小程序一枚
#!/usr/bin/env python # Import smtplib for the actual sending function import sys import getopt import smtplib sender = ‘liyiliang777@163.com‘ #这里输入发件人邮箱地址 # If there are more than one receiver, you need to ganerate a list. receiver = [‘aaa@sina.com‘,‘bbb@163.com‘] #这里输入收件人地址 cc_receiver = [‘abc@163.com‘] #这里输入抄送地址 server = ‘smtp.163.com‘ #邮件服务器发送地址 port = ‘25‘ #端口 pwd = ‘xxxx‘ #你的邮箱密码 COMMASPACE = ‘, ‘ # Import the email modules we‘ll need #from email.mime.text import MIMEText from email.MIMEText import MIMEText from email.Header import Header def usage(): usageStr = ‘‘‘Usage: SendEmail -s "subject" -c "mail_content"‘‘‘ print usageStr def 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 == ‘-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:])
发送邮件用法:
python sendmail.py -s "标题" -c "发送的内容"
本文出自 “Chocolee” 博客,请务必保留此出处http://chocolee.blog.51cto.com/8158455/1562520
python 发邮件小程序一枚
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。