send plain text mails -- not really clean, but useful :-/
This commit is contained in:
parent
c84c465a14
commit
417bd56b20
19
atomstrom.py
19
atomstrom.py
@ -26,18 +26,13 @@ import smtplib
|
|||||||
|
|
||||||
def send_mail(sender, receiver, subject, body):
|
def send_mail(sender, receiver, subject, body):
|
||||||
print 'sending to %s: %s' % (receiver[0], subject)
|
print 'sending to %s: %s' % (receiver[0], subject)
|
||||||
Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8')
|
message = 'From: "%s" <%s>\n' % (sender[0], sender[1])
|
||||||
mail = MIMEMultipart('alternative')
|
message += 'To: "%s" <%s>\n' % (receiver[0], receiver[1])
|
||||||
mail['Subject'] = "%s" % Header(subject, 'utf-8')
|
message += 'Subject: %s\n\n' % subject
|
||||||
mail['From'] = "\"%s\" <%s>" % (Header(sender[0], 'utf-8'), sender[1])
|
message += body.encode('utf-8')
|
||||||
mail['To'] = "\"%s\" <%s>" % (Header(receiver[0], 'utf-8'), receiver[1])
|
server = smtplib.SMTP('localhost')
|
||||||
textpart = MIMEText(body, 'plain', 'utf-8')
|
server.sendmail(sender[1], [receiver[1]], message)
|
||||||
mail.attach(textpart)
|
server.close()
|
||||||
str_io = StringIO()
|
|
||||||
gen = Generator(str_io, False)
|
|
||||||
gen.flatten(mail)
|
|
||||||
s = smtplib.SMTP('localhost')
|
|
||||||
s.sendmail("", receiver[1], str_io.getvalue())
|
|
||||||
|
|
||||||
def truncate_text(content, length=100, suffix='...'):
|
def truncate_text(content, length=100, suffix='...'):
|
||||||
content = " ".join(content.split())
|
content = " ".join(content.split())
|
||||||
|
Loading…
Reference in New Issue
Block a user