aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-11-25 07:55:49 +0100
committercedricbonhomme <devnull@localhost>2010-11-25 07:55:49 +0100
commit2bfc042b3b812ae2206918ad2c03e80141fd5e3e (patch)
tree84ce4928da0109951053679e1977a4b62ebd445b /utils.py
parentTypo. (diff)
downloadnewspipe-2bfc042b3b812ae2206918ad2c03e80141fd5e3e.tar.gz
newspipe-2bfc042b3b812ae2206918ad2c03e80141fd5e3e.tar.bz2
newspipe-2bfc042b3b812ae2206918ad2c03e80141fd5e3e.zip
E-mail notifications are now sent with an HTML content and with an alternative plain text version (MIMEMultipart).
Diffstat (limited to 'utils.py')
-rwxr-xr-xutils.py41
1 files changed, 28 insertions, 13 deletions
diff --git a/utils.py b/utils.py
index 2409563e..8a22b2be 100755
--- a/utils.py
+++ b/utils.py
@@ -44,6 +44,7 @@ except:
pass
import smtplib
+from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import urllib2
@@ -217,20 +218,34 @@ def send_mail(mfrom, mto, feed_title, article_title, description):
"""
Send the article via mail.
"""
- content = """<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n%s\n</body>\n</html>""" % \
+ # Create the body of the message (a plain-text and an HTML version).
+ html = """<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n%s\n</body>\n</html>""" % \
(feed_title + ": " + article_title, description)
- mail = MIMEText(content)
- mail['From'] = mfrom
- mail['To'] = mto
- mail['Subject'] = '[pyAggr3g470r] - ' + feed_title + ": " + article_title
- #email['Text'] = message
-
- server = smtplib.SMTP(smtp_server)
- server.login(username, password)
- server.sendmail(mfrom, \
- mto, \
- mail.as_string())
- server.quit()
+ text = clear_string(description)
+
+ # Create message container - the correct MIME type is multipart/alternative.
+ msg = MIMEMultipart('alternative')
+ msg['Subject'] = '[pyAggr3g470r] ' + feed_title + ": " + article_title
+ msg['From'] = mfrom
+ msg['To'] = mto
+
+ # Record the MIME types of both parts - text/plain and text/html.
+ part1 = MIMEText(text, 'plain')
+ part2 = MIMEText(html, 'html')
+
+ # Attach parts into message container.
+ # According to RFC 2046, the last part of a multipart message, in this case
+ # the HTML message, is best and preferred.
+ msg.attach(part1)
+ msg.attach(part2)
+
+ # Send the message via local SMTP server.
+ s = smtplib.SMTP(smtp_server)
+ s.login(username, password)
+ # sendmail function takes 3 arguments: sender's address, recipient's address
+ # and message to send - here it is sent as one string.
+ s.sendmail(mfrom, mto, msg.as_string())
+ s.quit()
def string_to_datetime(stringtime):
"""
bgstack15