本文整理汇总了Python中pyramid_mailer.message.Message.attach方法的典型用法代码示例。如果您正苦于以下问题:Python Message.attach方法的具体用法?Python Message.attach怎么用?Python Message.attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid_mailer.message.Message
的用法示例。
在下文中一共展示了Message.attach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_message_multipart_with_qpencoding
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def test_to_message_multipart_with_qpencoding(self):
from pyramid_mailer.message import Message, Attachment
response = Message(
recipients=['To'],
sender='From',
subject='Subject',
body='Body',
html='Html'
)
this = os.path.abspath(__file__)
with open(this, 'rb') as data:
attachment = Attachment(
filename=this,
content_type='application/octet-stream',
disposition='disposition',
transfer_encoding='quoted-printable',
data=data,
)
response.attach(attachment)
message = response.to_message()
payload = message.get_payload()[1]
self.assertEqual(
payload.get('Content-Transfer-Encoding'),
'quoted-printable'
)
self.assertEqual(
payload.get_payload(),
_qencode(self._read_filedata(this,'rb')).decode('ascii')
)
示例2: test_attach
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def test_attach(self):
from pyramid_mailer.message import Message
from pyramid_mailer.message import Attachment
msg = Message(
subject="testing",
recipients=["[email protected]"],
sender='sender',
body="testing"
)
attachment = Attachment(
data=b"this is a test",
content_type="text/plain"
)
msg.attach(attachment)
a = msg.attachments[0]
self.assertTrue(a.filename is None)
self.assertEqual(a.disposition, 'attachment')
self.assertEqual(a.content_type, "text/plain")
self.assertEqual(a.data, b"this is a test")
示例3: email
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def email(self):
id = self.request.matchdict['id']
test = Tests.by({'id':id,'alias':self.request.user.alias}).first()
if not test:
raise HTTPForbidden()
file = self._generate_pdf(id)
self.response['id'] = id
self.response['emails'] = self.request.params.get('email.addresses',None)
if 'form.submitted' in self.request.params:
if self.request.params['email.ok'] == '1':
emails = self.request.params['email.addresses'].replace(' ','').split(',')
for email in emails:
if not Validate.email(email):
self.notify('Invalid email address',warn=True)
return self.template('email.pt')
try:
message = Message(subject=self._email_fmt(id, str(Properties.get('MAILER_TO_SUBJECT','Submission'))),
sender=str(Properties.get('MAILER_GLOBAL_FROM_ADDRESS','System')),
recipients=emails,
body=self._email_fmt(id, str(Properties.get('MAILER_BODY','Submission'))))
attachment = Attachment('submission_' + str(id) + '.pdf', 'application/pdf', file)
message.attach(attachment)
mailer = get_mailer(self.request)
mailer.send(message)
self.notify('Email sent!')
except Exception as e:
print "ERROR: " + str(e)
self.notify('Unable to send email!',warn=True)
else:
self.notify('Unable to send example email!',warn=True)
return self.template('email.pt')
示例4: accountant_mail
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def accountant_mail(appstruct):
"""
this function returns a message object for the mailer
it consists of a mail body and an attachment attached to it
"""
unencrypted = make_mail_body(appstruct)
#print("accountant_mail: mail body: \n%s") % unencrypted
#print("accountant_mail: type of mail body: %s") % type(unencrypted)
encrypted = encrypt_with_gnupg(unencrypted)
#print("accountant_mail: mail body (enc'd): \n%s") % encrypted
#print("accountant_mail: type of mail body (enc'd): %s") % type(encrypted)
message = Message(
subject="[C3S] Yes! a new member",
sender="[email protected]",
recipients=["[email protected]"],
body=encrypted
)
#print("accountant_mail: csv_payload: \n%s") % generate_csv(appstruct)
#print(
# "accountant_mail: type of csv_payload: \n%s"
#) % type(generate_csv(appstruct))
csv_payload_encd = encrypt_with_gnupg(generate_csv(appstruct))
#print("accountant_mail: csv_payload_encd: \n%s") % csv_payload_encd
#print(
# "accountant_mail: type of csv_payload_encd: \n%s"
#) % type(csv_payload_encd)
attachment = Attachment(
"C3S-SCE-AFM.csv.gpg", "application/gpg-encryption",
csv_payload_encd)
message.attach(attachment)
return message
示例5: mailer_send
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def mailer_send(subject="!",
sender=None,
recipients=[],
body=None,
html=None,
attachments=[]):
try:
request = get_current_request()
if sender is None:
sender = request.registry.settings['mail.default_sender']
mailer = get_mailer(request)
message = Message(subject=subject,
sender=sender,
recipients=recipients,
body=body,
html=html)
for attachment in attachments:
attachment = Attachment(attachment.title,
attachment.mimetype,
attachment)
message.attach(attachment)
if transaction.get().status == Status.COMMITTED:
mailer.send_immediately(message)
else:
mailer.send(message)
except Exception:
pass
示例6: test_to_message_with_html_attachment
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def test_to_message_with_html_attachment(self):
from pyramid_mailer.message import Message, Attachment
response = Message(recipients=["To"], sender="From", subject="Subject", body="Body")
attachment = Attachment(data=b"data", content_type="text/html")
response.attach(attachment)
message = response.to_message()
att_payload = message.get_payload()[1]
self.assertEqual(att_payload["Content-Type"], 'text/html; charset="us-ascii"')
self.assertEqual(att_payload.get_payload(), _bencode(b"data").decode("ascii"))
示例7: test_to_message_with_binary_attachment
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def test_to_message_with_binary_attachment(self):
from pyramid_mailer.message import Message, Attachment
response = Message(recipients=["To"], sender="From", subject="Subject", body="Body")
data = os.urandom(100)
attachment = Attachment(data=data, content_type="application/octet-stream")
response.attach(attachment)
message = response.to_message()
att_payload = message.get_payload()[1]
self.assertEqual(att_payload["Content-Type"], "application/octet-stream")
self.assertEqual(att_payload.get_payload(), _bencode(data).decode("ascii"))
示例8: accountant_mail
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def accountant_mail(appstruct):
unencrypted = u"""
Yay!
we got a declaration of intent through the form: \n
firstname: \t\t %s
lastname: \t\t %s
email: \t\t %s
street & no: \t\t %s
address2: \t\t %s
postcode: \t\t %s
city: \t\t %s
country: \t\t %s
activities: \t\t %s
created3: \t\t $s
member of collecting society: %s
understood declaration text: %s
consider joining \t %s
noticed data protection: \t %s
that's it.. bye!""" % (
unicode(appstruct['firstname']),
unicode(appstruct['lastname']),
unicode(appstruct['email']),
unicode(appstruct['address1']),
unicode(appstruct['address2']),
unicode(appstruct['postCode']),
unicode(appstruct['city']),
unicode(appstruct['country']),
unicode(appstruct['at_least_three_works']),
unicode(appstruct['member_of_colsoc']),
unicode(appstruct['understood_declaration']),
unicode(appstruct['consider_joining']),
unicode(appstruct['noticed_dataProtection']),
)
message = Message(
subject="[c3s] Yes! a new letter of intent",
sender="[email protected]",
recipients=["[email protected]"],
body=str(encrypt_with_gnupg((unencrypted)))
)
attachment = Attachment("foo.gpg", "application/gpg-encryption",
unicode(encrypt_with_gnupg(u"foo to the bar!")))
# TODO: make attachment contents a .csv with the data supplied.
message.attach(attachment)
return message
示例9: mail_submission
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def mail_submission(context, request, appstruct):
mailer = get_mailer(request)
message = Message(subject=appstruct['subject'],
sender=appstruct['name'] + ' <' + appstruct['sender'] + '>',
extra_headers={'X-Mailer': "kotti_contactform"},
recipients=[context.recipient],
body=appstruct['content'])
if 'attachment' in appstruct and appstruct['attachment'] is not None:
message.attach(Attachment(
filename=appstruct['attachment']['filename'],
content_type=appstruct['attachment']['mimetype'],
data=appstruct['attachment']['fp']
))
mailer.send(message)
示例10: accountant_mail
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def accountant_mail(appstruct):
unencrypted = make_mail_body(appstruct)
message = Message(
subject="[c3s] Yes! a new letter of intent",
sender="[email protected]",
recipients=["[email protected]"],
body=unicode(encrypt_with_gnupg((unencrypted)))
)
attachment = Attachment("foo.gpg", "application/gpg-encryption",
unicode(encrypt_with_gnupg(u"foo to the bar!")))
# TODO: make attachment contents a .csv with the data supplied.
message.attach(attachment)
return message
示例11: test_send
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def test_send(self):
from pyramid_mailer.mailer import Mailer
from pyramid_mailer.message import Attachment
from pyramid_mailer.message import Message
mailer = Mailer()
msg = Message(subject="testing",
sender="[email protected]",
recipients=["[email protected]"],
body="test")
msg.attach(Attachment('test.txt',
data=b"this is a test",
content_type="text/plain"))
mailer.send(msg)
示例12: mail_submission
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def mail_submission(context, request, appstruct):
mailer = get_mailer(request)
message = Message(
subject=appstruct["subject"],
sender="{name} <{email}>".format(name=appstruct["name"], email=context.sender),
extra_headers={"X-Mailer": "kotti_contactform", "Reply-To": "{name} <{sender}>".format(**appstruct)},
recipients=[context.recipient],
body=appstruct["content"],
)
if "attachment" in appstruct and appstruct["attachment"] is not None:
message.attach(
Attachment(
filename=appstruct["attachment"]["filename"],
content_type=appstruct["attachment"]["mimetype"],
data=appstruct["attachment"]["fp"],
)
)
mailer.send(message)
示例13: test_to_message_multipart_with_qpencoding
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def test_to_message_multipart_with_qpencoding(self):
from pyramid_mailer.message import Message, Attachment
response = Message(recipients=["To"], sender="From", subject="Subject", body="Body", html="Html")
this = os.path.abspath(__file__)
data = open(this, "rb")
attachment = Attachment(
filename=this,
content_type="application/octet-stream",
disposition="disposition",
transfer_encoding="quoted-printable",
data=data,
)
response.attach(attachment)
message = response.to_message()
payload = message.get_payload()[1]
self.assertEqual(payload.get("Content-Transfer-Encoding"), "quoted-printable")
self.assertEqual(payload.get_payload(), _qencode(self._read_filedata(this, "rb")).decode("ascii"))
示例14: test_attach
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def test_attach(self):
from pyramid_mailer.message import Message
from pyramid_mailer.message import Attachment
msg = Message(subject="testing", recipients=["[email protected]"], body="testing")
msg.attach(Attachment(data="this is a test", content_type="text/plain"))
a = msg.attachments[0]
self.assertTrue(a.filename is None)
self.assertEqual(a.disposition, "attachment")
self.assertEqual(a.content_type, "text/plain")
self.assertEqual(a.data, "this is a test")
response = msg.get_response()
self.assertEqual(len(response.attachments), 1)
示例15: mail_submission
# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import attach [as 别名]
def mail_submission(context, request, appstruct):
mailer = get_mailer(request)
message = Message(
subject=appstruct['subject'],
sender='{name} <{email}>'.format(
name=appstruct['name'],
email=context.sender),
extra_headers={
'X-Mailer': "kotti_contactform",
'Reply-To': '{name} <{sender}>'.format(**appstruct),
},
recipients=[context.recipient],
body=appstruct['content'])
if 'attachment' in appstruct and appstruct['attachment'] is not None:
message.attach(Attachment(
filename=appstruct['attachment']['filename'],
content_type=appstruct['attachment']['mimetype'],
data=appstruct['attachment']['fp']
))
mailer.send(message)