本文整理汇总了Python中envelopes.Envelope.add_to_addr方法的典型用法代码示例。如果您正苦于以下问题:Python Envelope.add_to_addr方法的具体用法?Python Envelope.add_to_addr怎么用?Python Envelope.add_to_addr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类envelopes.Envelope
的用法示例。
在下文中一共展示了Envelope.add_to_addr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReplyMail
# 需要导入模块: from envelopes import Envelope [as 别名]
# 或者: from envelopes.Envelope import add_to_addr [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__