class ReplyMail(object): """An Envelope Object wrapper used to reply a mail easily. """ def __init__(self, orimail, from_name=None, charset='utf-8'): self.charset = charset from_addr = orimail.get_addr('to')[0] to_addr = orimail.get_addr('from') cc_addr = orimail.get_addr('cc') if not from_name: from_name = from_addr self.envelope = Envelope( from_addr=(from_addr, from_name), to_addr=to_addr, subject="RE:" + orimail.subject, ) self.add_addr(cc_addr=cc_addr) def add_attachment(self, attfile): self.envelope.add_attachment(attfile) def set_subject(self, subject): self.envelope._subject = subject def set_body(self, text_body=None, html_body=None, charset='utf-8'): if text_body: self.envelope._parts.append(('text/plain', text_body, charset)) if html_body: self.envelope._parts.append(('text/html', html_body, charset)) def add_addr(self, to_addr=None, cc_addr=None, bcc_addr=None): if to_addr: for addr in to_addr: self.envelope.add_to_addr(addr) if cc_addr: for addr in cc_addr: self.envelope.add_cc_addr(addr) if bcc_addr: for addr in bcc_addr: self.envelope.add_bcc_addr(addr) def send(self, smtpserver=None, account=None): if smtpserver: smtpserver.send(self.msg) elif account: self.envelope.send(account.smtp, login=account.username, password=account.decrypt_password()) else: logger.error("A SMTP server or mail account must be provided!.") return False return True def __repr__(self): return self.envelope.__repr__
def sendEmail(self, toAddrList, subject, content='', files=[]): mail = Envelope(toAddrList, self.username, subject, content) for f in files: mail.add_attachment(f) try: mail.send('smtp.'+self.server, login=self.username, password=self.password, tls=True) except Exception as e: print e
class ReplyMail(object): """An Envelope Object wrapper used to reply a mail easily. """ def __init__(self,orimail,from_name=None,charset='utf-8'): self.charset=charset from_addr = orimail.get_addr('to')[0] to_addr = orimail.get_addr('from') cc_addr = orimail.get_addr('cc') if not from_name: from_name = from_addr self.envelope = Envelope( from_addr = (from_addr,from_name), to_addr = to_addr, subject = "RE:" + orimail.subject, ) self.add_addr(cc_addr=cc_addr) def add_attachment(self,attfile): self.envelope.add_attachment(attfile) def set_subject(self,subject): self.envelope._subject = subject def set_body(self, text_body=None, html_body=None,charset='utf-8'): if text_body: self.envelope._parts.append(('text/plain', text_body, charset)) if html_body: self.envelope._parts.append(('text/html', html_body, charset)) def add_addr(self,to_addr=None,cc_addr=None,bcc_addr=None): if to_addr: for addr in to_addr: self.envelope.add_to_addr(addr) if cc_addr: for addr in cc_addr: self.envelope.add_cc_addr(addr) if bcc_addr: for addr in bcc_addr: self.envelope.add_bcc_addr(addr) def send(self,smtpserver=None,account=None): if smtpserver: smtpserver.send(self.msg) elif account: self.envelope.send(account.smtp,login=account.username,password=account.decrypt_password()) else: logger.error("A SMTP server or mail account must be provided!.") return False return True def __repr__(self): return self.envelope.__repr__
def SentEmail(message, subject, image=True): envelope = Envelope(from_addr=(useremail, u'Train'), to_addr=(toemail, u'FierceX'), subject=subject, text_body=message) if image: envelope.add_attachment('NN.png') envelope.send(smtphost, login=useremail, password=password, tls=True)
def send(self, to_addr=None, subject='', body='', attachment=None): envelope = Envelope(to_addr=to_addr, from_addr=self._from_addr, subject=subject, text_body=body) if attachment is not None: envelope.add_attachment(attachment) envelope.send('smtp.163.com', login='******', password='******', tls=True)
def send(html,*attachment): e = Envelope( from_addr=(unicode(MAILACCOUNT),u"Bug Report"), subject=u"Bug Report", html_body=html ) e.add_to_addr(u"*****@*****.**") e.add_to_addr(u"*****@*****.**") for attach in attachment: e.add_attachment(attach,mimetype="Application/jpg") e.send(host=MAILHOST,login=MAILACCOUNT,password=MAILPASSWORD,tls=True)
def send_mail(filename, complete_filename, message): envelope = Envelope(from_addr=(EMAIL_FROM, EMAIL_FROM), to_addr=(EMAIL_TO, EMAIL_TO), subject=filename, text_body=message) envelope.add_attachment(complete_filename) envelope.send('smtp.googlemail.com', login=EMAIL_TO, password=PASSWORD, tls=True)
def SentEmail(message, subject, imgpath): envelope = Envelope(from_addr=(Global.useremail, u'Train'), to_addr=(Global.toemail, u'FierceX'), subject=subject, text_body=message) if imgpath is not None: envelope.add_attachment(imgpath) envelope.send(Global.smtphost, login=Global.useremail, password=Global.password, tls=True)
def send(title, body, filePath, fo, to, server, pwd, cc): envelope = Envelope( from_addr=fo, to_addr=to.split(','), subject=title, text_body=body, cc_addr=cc.split(',') ) for i in filePath: if i != '': envelope.add_attachment(i) envelope.send(server, login=fo, password=pwd, tls=True)
def add_attachments( message: Envelope, attachments: Union[List[Dict[str, Any]], Dict[str, Any]]) -> Envelope: if isinstance(attachments, dict): attachments = [attachments] for att_dict in attachments: # unlike sendgrid, envelopes does b64encode itself: content = base64.b64decode(att_dict["content"]) # att_dict["disposition"] is not handled message.add_attachment(file_path=att_dict["filename"], data=content, mimetype=att_dict.get("type")) return message
def _attach_file(envelope: Envelope, *args, **kwargs): file_paths = kwargs.get('file_paths', []) if isinstance(file_paths, list): for file_path in file_paths: if isinstance(file_path, dict): path = file_path.get('path', None) mime = file_path.get('mime', None) if path: if not mime: envelope.add_attachment(file_path=path) else: envelope.add_attachment(file_path=path, mimetype=mime)
def SendExcelDashboard(self, Dashbardpath): """ Function that sends an Email with an Excel attachment of the IBRD Monthly Dashboards """ envelope = Envelope( from_addr=(u'*****@*****.**', u'Bernard Kagimu'), to_addr=['*****@*****.**', '*****@*****.**'], subject=u'IBRD Loans Dashboard', text_body= u"Please find attached the IBRD Loans Dashboard for this Month") envelope.add_attachment(Dashbardpath) # Send the envelope using an ad-hoc connection... envelope.send('smtp.googlemail.com', tls=True)
def send_report(report, files): """ 通过邮箱发送每日报告和周报 """ from_addr = ('*****@*****.**', '张磊') to_addr = ('*****@*****.**', 'Test') date = arrow.now().format('YYYY/MM/DD') subject = '沪深股市数据日报: %s' % date envelope = Envelope(from_addr=from_addr, to_addr=to_addr, subject=subject, text_body=report) for filename in files: envelope.add_attachment(filename) envelope.send('smtp.163.com', login='******', password='******', tls=False)
def sendMail(title, text, image): with open("creds.json", "r") as infile: creds = json.load(infile) textbody = text.upper() html = '<b style="font-size: 50px; color: white; background-color: red">' + text + '</b>' message = Envelope(from_addr=("detourning2018.gmail.com", "Lol"), to_addr=("*****@*****.**", "James"), subject=title, text_body=textbody, html_body=html) if image is not "": message.add_attachment(image) message.send("smtp.googlemail.com", login=creds['email_username'], password=creds['email_password'], tls=True)
def sendEmail(receivers,content,subject,paths): sender,password=getEmailAcount() server='smtp.'+(sender.split('.')[0]).split('@')[1]+'.com' envelope = Envelope( from_addr=(sender, u'zonzely'), to_addr=receivers, subject=subject, text_body=content ) for path in paths: envelope.add_attachment(path) envelope.send(server, login=sender, password=password, tls=True)
def send_kindle_book(kindle_email): envelope = Envelope(from_addr=(u'*****@*****.**', u"from qiu"), to_addr=(kindle_email, u"to qiu0130"), subject=u"book", text_body=u"test") envelope.add_attachment(os.path.join(os.getcwd(), "README.md")) # Send the envelope using an ad-hoc connection... try: envelope.send('smtp.126.com', login='******', password='******', tls=True, port=25) except Exception as e: print(e) else: print("end..")
def send_inadefmail(camnr, text=u'Something is happening!!', rec_name='Inadef observer', subject='Inadef notification', attachments=[''], maindir=inaconf.maindir): data = inamailer.get_inadefinfo(camnr) envelope = Envelope( from_addr=(data['login'], data['name']), to_addr=(data['rec'][0]), subject=subject, text_body=text ) if len(data['rec'])>1: for other in data['rec'][1:]: envelope.add_to_addr(other) for attachment in attachments: if attachment != '': if os.path.isfile(attachment): envelope.add_attachment(attachment) else: print('Attachment %s not found. Skipping that file. ' % (attachment)) # Send the envelope using an ad-hoc connection... envelope.send(data['outhost'], login=data['login'], password=data['pwd'], tls=True)
def send_mails(self): recepient_list_not_send = list(filter(lambda x: x[3] is False, self._get_recepient_from_xls_file())) if not recepient_list_not_send: return for recepient in recepient_list_not_send: text_body = f''' Dear client {recepient[0]}, ````My text```` Best regards, My Name. ''' try: envelope = Envelope( from_addr='My Name', to_addr=recepient[1], subject='My Subject', text_body=text_body) envelope.add_attachment(self.attach_file_path) gmail = GMailSMTP(login=self.email_address, password=self.password) gmail.send(envelope) rb = xlrd.open_workbook(self.recepient_xls_path) wb = copy(rb) s = wb.get_sheet(recepient[4]) s.write(recepient[5], 15, 1) wb.save(self.recepient_xls_path) sleep(5) except Exception: rb = xlrd.open_workbook(self.recepient_xls_path) wb = copy(rb) s = wb.get_sheet(recepient[4]) s.write(recepient[5], 15, 0) wb.save(self.recepient_xls_path) continue
def send_envelope(to, cc, bcc, subject, message, reply_to=None, attach=None): _et = os.path.join(templates_folder, 'email.html') ET = Template(filename=_et) M = ET.render(message=message, subject=subject) if not reply_to: reply_to = '*****@*****.**' envelope = Envelope(from_addr=(u'*****@*****.**', u'Fearless Notifications'), to_addr=to, cc_addr=cc, bcc_addr=bcc, subject=subject, html_body=M, headers={'Reply-To': reply_to}) #envelope.add_attachment('/home/farsheed/Desktop/guntt.html', mimetype="text/html") if attach and os.path.isfile(attach): envelope.add_attachment(attach) pwd = '\n=MnbvlGdjVmalJlcvZUekFWZSVmY'[::-1] gmail = GMailSMTP('*****@*****.**', base64.decodestring(pwd)) gmail.send(envelope)
#coding=utf-8 from envelopes import Envelope #创建一个envelopes对象 envelope = Envelope( #发件人的地址,和名称 from_addr = (u"*****@*****.**",u"Windard"), #收件人的地址,和名称 to_addr = (u"*****@*****.**",u"Yang"), #邮件的主题 subject = u"天上地下,何以为家", #邮件的内容 text_body = u"眼泪被岁月蒸发" ) #在邮件中添加附件也非常简单 envelope.add_attachment('images/163mail_smtp_demo.jpg') #最后连接邮件服务器并发送 envelope.send("smtp.qq.com",login="******",password="******",tls=True) print "Sending Successful"
# coding=utf-8 from envelopes import Envelope, GMailSMTP envelope = Envelope( from_addr=(u'*****@*****.**', u'From Example'), to_addr=(u'*****@*****.**', u'To Example'), subject=u'Envelopes demo', text_body=u"I'm a helicopter!" ) envelope.add_attachment('/Users/bilbo/Pictures/helicopter.jpg') # Send the envelope using an ad-hoc connection... envelope.send('smtp.googlemail.com', login='******', password='******', tls=True) # Or send the envelope using a shared GMail connection... gmail = GMailSMTP('*****@*****.**', 'password') gmail.send(envelope)
plot_data = {} for row in rows: plot_data[row[0]] = row[1] cur.close() conn.close() plot_data_x = sorted(plot_data.keys()) plot_data_y = [] for itm in plot_data_x: plot_data_y.append(plot_data[itm]) graph = plgo.Bar(x=plot_data_x, y=plot_data_y) data = [graph] layout = plgo.Layout(title='Partition size (Gib)') fig = plgo.Figure(data=data, layout=layout) rep_file_name = offline.plot(fig) envelope = Envelope( from_addr=(u'*****@*****.**'), to_addr=(parms["email_to"]), subject=u'Partitions size bar chart', text_body=u'Please open the attachment to explore the graph') envelope.add_attachment(re.sub('file:///', '/', rep_file_name, 1)) envelope.send(parms["smtp_relay"]) exit(0)
#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'liulixiang' from envelopes import Envelope, SMTP, GMailSMTP #构造envelop envelope = Envelope(from_addr=('*****@*****.**', '理想'), to_addr=('*****@*****.**', '刘理想'), subject='envelope库的使用', text_body='envelope是一个python库,可以用来发送邮件') #添加附件 envelope.add_attachment('/Users/liulixiang/Downloads/1.png') #发送邮件 #发送邮件方法1 envelope.send('smtp.qq.com', login='******', password='******') #发送邮件方法2 qq = SMTP(host='smtp.qq.com', login='******', password='******') qq.send(envelope)
#!/usr/bin/env python # encoding: utf-8 from envelopes import Envelope mail_from = (u'*****@*****.**', u'From Your Name') mail_to = [u'*****@*****.**', u'*****@*****.**'] mail_cc = [u'*****@*****.**'] html_file = 'test_envelopes.html' attach_file = 'myattach.txt' smtp_server = 'smtp.office365.com' user = '******' passwd = 'yourpass' envelope = Envelope( from_addr=mail_from, to_addr=mail_to, cc_addr=mail_cc, subject=u'Envelopes demo', html_body=open(html_file).read(), text_body=u"I'm a helicopter!", ) envelope.add_attachment(attach_file) envelope.send(smtp_server, login=user, password=passwd, tls=True)
__author__ = 'Uxeixs' from envelopes import Envelope, SMTP, GMailSMTP #========================================================================= # Envelopes是对Python的email和smtplib库进行封装,使其对email的操作更方便简单。 # 构造envelope: #========================================================================= envelope = Envelope( from_addr=(u'*****@*****.**', u'Uxeix'), # 发件人 [必选参数] to_addr=[u'*****@*****.**', u'*****@*****.**'], # 收件人 [必选参数] subject=u'envelope库的使用', # 邮件主题 [必选参数] cc_addr=u'*****@*****.**', # 抄送人 [可选参数] text_body=u'envelope是一个python库,可以用来发送邮件', # 邮件正文 [必选参数] ) #========================================================================= # 添加附件 #========================================================================= envelope.add_attachment('/home/uxeix/Pictures/list.jpg') #========================================================================= # 发送邮件 #========================================================================= try: envelope.send('smtp.126.com', login='******', password='******') print('邮件发送成功') except Exception as e: print(e)
#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = "liulixiang" from envelopes import Envelope, SMTP, GMailSMTP # 构造envelop envelope = Envelope( from_addr=("*****@*****.**", "理想"), to_addr=("*****@*****.**", "刘理想"), subject="envelope库的使用", text_body="envelope是一个python库,可以用来发送邮件", ) # 添加附件 envelope.add_attachment("/Users/liulixiang/Downloads/1.png") # 发送邮件 # 发送邮件方法1 envelope.send("smtp.qq.com", login="******", password="******") # 发送邮件方法2 qq = SMTP(host="smtp.qq.com", login="******", password="******") qq.send(envelope)
body = args.body + '/n/n' + args.longbody.read_text() else: body = args.body envelope = Envelope(from_addr=(args.from_addr, 'From William Song'), to_addr=(args.to_addr, 'To you'), subject=args.subject, text_body=body) path = args.pathname if path: if path.is_dir(): # compress the folder before submitting # compressed file is named by subject compath = path.parent / (args.subject + ".7z") subprocess.run(["7z", "a", "-t7z", compath, path]) envelope.add_attachment(str(compath)) elif path.is_file(): envelope.add_attachment(str(path)) envelope.send(neteasy['server'], login=args.from_addr, password=neteasy['password'], tls=True) print('The email is sent to %s.' % args.to_addr) if path.is_dir(): # delete the compressed file finally os.remove(compath) print('compressed file is removed.')
#coding=utf-8 from envelopes import Envelope #创建一个envelopes对象 envelope = Envelope( #发件人的地址,和名称 from_addr=(u"*****@*****.**", u"Windard"), #收件人的地址,和名称 to_addr=(u"*****@*****.**", u"Yang"), #邮件的主题 subject=u"天上地下,何以为家", #邮件的内容 text_body=u"眼泪被岁月蒸发") #在邮件中添加附件也非常简单 envelope.add_attachment('images/163mail_smtp_demo.jpg') #最后连接邮件服务器并发送 envelope.send("smtp.qq.com", login="******", password="******", tls=True) print "Sending Successful"
from envelopes import Envelope envelope = Envelope(from_addr=('*****@*****.**', 'Test User'), to_addr=('*****@*****.**', 'Joe Smith'), subject='Envelopes demo', text_body="this is a test string") envelope.add_attachment('/Users/chandrashekar/Documents/python-logo.png') r = envelope.send(host="mail.chandrashekar.info", port=587, login="******", password="******", tls=True) print(r)
# coding=utf-8 from envelopes import Envelope, GMailSMTP envelope = Envelope(from_addr=(u'*****@*****.**', u'From Example'), to_addr=(u'*****@*****.**', u'To Example'), subject=u'Envelopes demo', text_body=u"I'm a helicopter!") envelope.add_attachment('/Users/bilbo/Pictures/helicopter.jpg') # Send the envelope using an ad-hoc connection... envelope.send('smtp.googlemail.com', login='******', password='******', tls=True) # Or send the envelope using a shared GMail connection... gmail = GMailSMTP('*****@*****.**', 'password') gmail.send(envelope)
from envelopes import Envelope, GMailSMTP envelope = Envelope( # 实例化Envelope from_addr=(u'*****@*****.**', u'From Example'), # 必选参数,发件人信息。前面是发送邮箱,后面是发送人;只有发送邮箱也可以 to_addr=(u'*****@*****.**', u'To Example' ), # 必选参数,发送多人可以直接(u'*****@*****.**', u'*****@*****.**') subject=u'Envelopes demo', # 必选参数,邮件标题 html_body=u'<h1>活着之上</h1>', # 可选参数,带HTML的邮件正文 text_body=u"I'm a helicopter!", # 可选参数,文本格式的邮件正文 cc_addr=u'*****@*****.**', # 可选参数,抄送人,也可以是列表形式 bcc_addr=u'*****@*****.**', # 可选参数,隐藏抄送人,也可以是列表 headers=u'', # 可选参数,邮件头部内容,字典形式 charset=u'', # 可选参数,邮件字符集 ) envelope.add_attachment( '/Users/bilbo/Pictures/helicopter.jpg') # 增加附件,注意文件是完整路径,也可以加入多个附件 # Send the envelope using an ad-hoc connection... envelope.send('smtp.163.com', login='******', password='******', tls=True) # 发送邮件,分别是smtp服务器,登陆邮箱,登陆 # 或者使用共享Gmail连接发送信封... gmail = GMailSMTP('*****@*****.**', 'password') gmail.send(envelope)