#working version as external method # -*- coding: iso-8859-1 -*-
from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText
def htmlMailer(self): e_subject = u'Sent to you through plone' e_from = u'some@spammer.com' e_to = u'some@receiver.com' body_html = """<html>provsprängningen <em>av</em> kärnvapen</html>""" body_plain = u'provsprängningen *av* kärnvapen'
mime_msg = MIMEMultipart('related') mime_msg['Subject'] = e_subject mime_msg['From'] = e_from mime_msg['To'] = e_to mime_msg.preamble = 'This is a multi-part message in MIME format.'
# Encapsulate the plain and HTML versions of the message body # in an 'alternative' part, so message agents can decide # which they want to display. msgAlternative = MIMEMultipart('alternative') mime_msg.attach(msgAlternative)
# plain part msg_txt = MIMEText(body_plain, _charset='iso-8859-1') msgAlternative.attach(msg_txt)
# html part msg_txt = MIMEText(body_html, _subtype='html', _charset='iso-8859-1') msgAlternative.attach(msg_txt)
Comment
#working version as external method
# -*- coding: iso-8859-1 -*-
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
def htmlMailer(self):
e_subject = u'Sent to you through plone'
e_from = u'some@spammer.com'
e_to = u'some@receiver.com'
body_html = """<html>provsprängningen <em>av</em> kärnvapen</html>"""
body_plain = u'provsprängningen *av* kärnvapen'
mime_msg = MIMEMultipart('related')
mime_msg['Subject'] = e_subject
mime_msg['From'] = e_from
mime_msg['To'] = e_to
mime_msg.preamble = 'This is a multi-part message in MIME format.'
# Encapsulate the plain and HTML versions of the message body
# in an 'alternative' part, so message agents can decide
# which they want to display.
msgAlternative = MIMEMultipart('alternative')
mime_msg.attach(msgAlternative)
# plain part
msg_txt = MIMEText(body_plain, _charset='iso-8859-1')
msgAlternative.attach(msg_txt)
# html part
msg_txt = MIMEText(body_html, _subtype='html',
_charset='iso-8859-1')
msgAlternative.attach(msg_txt)
self.MailHost.send(mime_msg.as_string())