send plain text mails -- not really clean, but useful :-/

This commit is contained in:
Ronald Schaten 2013-04-05 21:16:56 +02:00
parent c84c465a14
commit 417bd56b20

View File

@ -26,18 +26,13 @@ import smtplib
def send_mail(sender, receiver, subject, body):
print 'sending to %s: %s' % (receiver[0], subject)
Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8')
mail = MIMEMultipart('alternative')
mail['Subject'] = "%s" % Header(subject, 'utf-8')
mail['From'] = "\"%s\" <%s>" % (Header(sender[0], 'utf-8'), sender[1])
mail['To'] = "\"%s\" <%s>" % (Header(receiver[0], 'utf-8'), receiver[1])
textpart = MIMEText(body, 'plain', 'utf-8')
mail.attach(textpart)
str_io = StringIO()
gen = Generator(str_io, False)
gen.flatten(mail)
s = smtplib.SMTP('localhost')
s.sendmail("", receiver[1], str_io.getvalue())
message = 'From: "%s" <%s>\n' % (sender[0], sender[1])
message += 'To: "%s" <%s>\n' % (receiver[0], receiver[1])
message += 'Subject: %s\n\n' % subject
message += body.encode('utf-8')
server = smtplib.SMTP('localhost')
server.sendmail(sender[1], [receiver[1]], message)
server.close()
def truncate_text(content, length=100, suffix='...'):
content = " ".join(content.split())