本文整理汇总了Python中email.message.EmailMessage.get_payload方法的典型用法代码示例。如果您正苦于以下问题:Python EmailMessage.get_payload方法的具体用法?Python EmailMessage.get_payload怎么用?Python EmailMessage.get_payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.message.EmailMessage
的用法示例。
在下文中一共展示了EmailMessage.get_payload方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_email
# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import get_payload [as 别名]
def send_email(
email_from: str,
email_to: str,
location: Location,
screenshot: MapScreenshot,
template: str = None,
) -> None:
"""
Send the traffic info email.
Args:
email_from: Email sender's address.
email_to: Email recipient's address.
location: The map's location.
screenshot: The map's screenshot.
template: The path to the email's Jinja2 template,
templates/email.j2 if not specified.
"""
if template is None:
template = os.path.join(DIR, "templates", "email.j2")
logger = logging.getLogger(__name__)
map_cid = make_msgid()
context: Context = {
"url": f"https://www.google.fr/maps/@{location.latitude},"
f"{location.longitude},{location.zoom}z/data=!5m1!1e1",
"width": screenshot.width,
"height": screenshot.height,
"map_cid": map_cid[1:-1],
}
content = f"""
Today's traffic conditions.
{context["url"]}
Have a safe trip back home!
"""
html = render_template(template, context)
email = EmailMessage()
email["Subject"] = "Traffic info"
email["From"] = Address("Traffic info", addr_spec=email_from)
email["To"] = email_to
email.set_content(content)
email.add_alternative(html, subtype="html")
with open(screenshot.path, "rb") as img:
email.get_payload()[1].add_related(img.read(), "image", "png", cid=map_cid)
try:
with smtplib.SMTP("localhost") as smtp:
smtp.send_message(email)
except ConnectionRefusedError as exception:
logger.error("Unable to send email(%s)", exception)
示例2: deliver_email
# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import get_payload [as 别名]
def deliver_email(self, id, rx, msgbody, status_recorder):
''' gateway gives us plenty of info, what we want out of it is:
date_created, error_code, error_message, sid, status
we'll parse the error_code and error_message and return them in sendStatus
'''
urgheaders = [
('Priority','Urgent'),
('X-Priority','1 (Highest)'),
('Importance','High'),
('X-MMS-Priority','Urgent')
]
emailheaders = [
('To', 'SMVFD'),
('From', 'DispatchBuddy <[email protected]>'),
('Subject', 'Fire Dispatch: {address}'.format(address=self.evdict['address'])),
]
send_results = []
now = datetime.datetime.utcnow()
msg = EmailMessage()
for h,v in emailheaders:
msg[h]=v
msg.set_content('This is an HTML only email')
magnify_icon_cid = make_msgid()
medias = []
fdict = {'meta_icons':'', 'magnify_icon_cid':magnify_icon_cid[1:-1]}
self.logger.debug('ADD MMS urls, search for keys in: {}'.format(self.evdict['nature']))
for rk in sorted(media_urls):
if re.search(rk, self.evdict['nature']) or re.search(rk, self.evdict['notes']):
self.logger.debug('found key: {}'.format(rk))
media = media_urls.get(rk)
if not media:
media = media_urls['UNKNOWN']
media = 'https://southmeriden-vfd.org/images/dispatchbuddy/icon-'+media
medias.append(media)
medias = set(medias)
self.logger.debug('media urls: {}'.format(medias))
meta_icons_t = ''
if medias:
meta_icons_t = ''
for url in medias:
meta_icons_t += '<img class="meta_icons" src="{url}">'.format(url=url)
fdict.update({'meta_icons':meta_icons_t})
for kw in ('meta_icons', 'magnify_icon_cid'):
msgbody = msgbody.replace('{{'+kw+'}}','{'+kw+'}')
msgbody = msgbody.format(**fdict)
# now replace all the {{ and }}
msgbody = msgbody.replace('{{','{').replace('}}','}')
msg.add_alternative(msgbody, subtype='html')
with open('/var/bluelabs/DispatchBuddy/images/magnify.gif', 'rb') as img:
msg.get_payload()[1].add_related(img.read(), 'image', 'gif', cid=magnify_icon_cid)
'''
related = MIMEMultipart(_subtype='related')
innerhtml = MIMEText(msgbody, _subtype='html')
related.attach(innerhtml)
related.attach(icon_magnify_gif)
'''
for h,v in urgheaders:
msg[h]=v
bcc = [r.address for r in rx]
'''
medias = []
if self.mediatype == 'mms':
for rk in sorted(media_urls):
if re.search(rk, self.evdict['nature']) or re.search(rk, self.evdict['notes']):
media = media_urls.get(rk)
if not media:
media = media_urls['UNKNOWN']
media = 'https://southmeriden-vfd.org/images/dispatchbuddy/'+media
args['media_url'] = medias
print('args list: {}'.format(args))
'''
host = self.config.get('SMTP', 'host')
ehlo = self.config.get('SMTP', 'ehlo')
user = self.config.get('SMTP', 'user')
pass_ = self.config.get('SMTP', 'pass')
from_ = self.config.get('SMTP', 'from')
#.........这里部分代码省略.........
示例3: make_msgid
# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import get_payload [as 别名]
# message as the second part.
asparagus_cid = make_msgid()
msg.add_alternative("""\
<html>
<head></head>
<body>
<p>Salut!<\p>
<p>Cela ressemble à un excellent
<a href="http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718>
recipie
</a> déjeuner.
</p>
<img src="cid:{asparagus_cid}" \>
</body>
</html>
""".format(asparagus_cid=asparagus_cid[1:-1]), subtype='html')
# note that we needed to peel the <> off the msgid for use in the html.
# Now add the related image to the html part.
with open("roasted-asparagus.jpg", 'rb') as img:
msg.get_payload()[1].add_related(img.read(), 'image', 'jpeg',
cid=asparagus_cid)
# Make a local copy of what we are going to send.
with open('outgoing.msg', 'wb') as f:
f.write(bytes(msg))
# Send the message via local SMTP server.
with smtplib.SMTP('localhost') as s:
s.send_message(msg)
示例4: open
# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import get_payload [as 别名]
</ul>
</li>
</ul>
LabResult<br>
Tel : 07 82 42 32 12
<br>
<img src="cid:{logo_cid}" \>
</body>
</html>
""".format(logo_cid=logo_cid[1:-1]), subtype='html')
# note that we needed to peel the <> off the msgid for use in the html.
# Now add the related image to the html part.
with open("logo.png", 'rb') as img:
msg.get_payload()[1].add_related(img.read(), 'logo', 'png',
cid=logo_cid)
# Make a local copy of what we are going to send.
with open('outgoing.msg', 'wb') as f:
f.write(bytes(msg))
msg2 = MIMEText("Envoi des identifians de démo à %s" % recipient)
msg2['Subject'] = "Connexion démo LabResult "
msg2['From'] = "[email protected]"
msg2['To'] = "[email protected]"
# Send the message via local SMTP server.
with smtplib.SMTP_SSL('mail.gandi.net') as s:
s.login(USERNAME, PASSWORD)
s.send_message(msg)
s.send_message(msg2)