send emails properly encoded and with text/plain and text/html parts

This commit is contained in:
Frédéric Péters 2005-05-19 21:47:24 +00:00
parent 94d3df3ada
commit 8b88d1d78e
1 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,6 @@
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.Header import Header
import smtplib
try:
@ -90,12 +91,19 @@ link: %(url)s
except IOError:
htmlmail = None
msg = MIMEText(mail_body, _charset = 'iso-8859-15')
msg['Subject'] = _("A new form has been submitted")
msg = MIMEMultipart(_charset = 'iso-8859-15', _subtype = 'alternative')
msg['Subject'] = Header(_("A new form has been submitted"), 'iso-8859-15')
msg['To'] = self.emailrcpt
msg['From'] = 'WCS <noreply@entrouvert.com>'
msg['X-Mailer'] = 'w.c.s.'
msg.preamble = ''
msg.epilogue = ''
msg.attach(MIMEText(mail_body, _charset = 'iso-8859-15'))
if htmlmail:
msg.attach(MIMEText(htmlmail, _subtype = 'html'))
s = smtplib.SMTP()
s.connect()
s.sendmail('noreply@entrouvert.com', [msg['To']], msg.as_string())