本文整理汇总了Python中envelopes.Envelope.add_attachment方法的典型用法代码示例。如果您正苦于以下问题:Python Envelope.add_attachment方法的具体用法?Python Envelope.add_attachment怎么用?Python Envelope.add_attachment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类envelopes.Envelope
的用法示例。
在下文中一共展示了Envelope.add_attachment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReplyMail
# 需要导入模块: from envelopes import Envelope [as 别名]
# 或者: from envelopes.Envelope import add_attachment [as 别名]
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__
示例2: sendEmail
# 需要导入模块: from envelopes import Envelope [as 别名]
# 或者: from envelopes.Envelope import add_attachment [as 别名]
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)
示例3: Envelope
# 需要导入模块: from envelopes import Envelope [as 别名]
# 或者: from envelopes.Envelope import add_attachment [as 别名]
# coding=utf-8
from envelopes import Envelope, GMailSMTP
envelope = Envelope(
from_addr=(u'[email protected]', u'From Example'),
to_addr=(u'[email protected]', 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='[email protected]',
password='password', tls=True)
# Or send the envelope using a shared GMail connection...
gmail = GMailSMTP('[email protected]', 'password')
gmail.send(envelope)
示例4: Envelope
# 需要导入模块: from envelopes import Envelope [as 别名]
# 或者: from envelopes.Envelope import add_attachment [as 别名]
#!/usr/bin/env python
# encoding: utf-8
from envelopes import Envelope
mail_from = (u'[email protected]', u'From Your Name')
mail_to = [u'[email protected]', u'[email protected]']
mail_cc = [u'[email protected]']
html_file = 'test_envelopes.html'
attach_file = 'myattach.txt'
smtp_server = 'smtp.office365.com'
user = '[email protected]'
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)
示例5: Envelope
# 需要导入模块: from envelopes import Envelope [as 别名]
# 或者: from envelopes.Envelope import add_attachment [as 别名]
#coding=utf-8
from envelopes import Envelope
#创建一个envelopes对象
envelope = Envelope(
#发件人的地址,和名称
from_addr = (u"[email protected]",u"Windard"),
#收件人的地址,和名称
to_addr = (u"[email protected]",u"Yang"),
#邮件的主题
subject = u"天上地下,何以为家",
#邮件的内容
text_body = u"眼泪被岁月蒸发"
)
#在邮件中添加附件也非常简单
envelope.add_attachment('images/163mail_smtp_demo.jpg')
#最后连接邮件服务器并发送
envelope.send("smtp.qq.com",login="[email protected]",password="XXXXXX",tls=True)
print "Sending Successful"
示例6: Envelope
# 需要导入模块: from envelopes import Envelope [as 别名]
# 或者: from envelopes.Envelope import add_attachment [as 别名]
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = "liulixiang"
from envelopes import Envelope, SMTP, GMailSMTP
# 构造envelop
envelope = Envelope(
from_addr=("[email protected]", "理想"),
to_addr=("[email protected]", "刘理想"),
subject="envelope库的使用",
text_body="envelope是一个python库,可以用来发送邮件",
)
# 添加附件
envelope.add_attachment("/Users/liulixiang/Downloads/1.png")
# 发送邮件
# 发送邮件方法1
envelope.send("smtp.qq.com", login="[email protected]", password="123")
# 发送邮件方法2
qq = SMTP(host="smtp.qq.com", login="[email protected]", password="123")
qq.send(envelope)