summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-09-06 11:11:50 -0600
committerAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-09-06 11:11:50 -0600
commitb4d29815802adb1b01e1c7e3e4c7ad43d5f7276e (patch)
treeddcc95d8db894100d49612345a754edf44919d53
parent996507782f455c17afcf68667ad83c963a9179c7 (diff)
downloadaskbot-b4d29815802adb1b01e1c7e3e4c7ad43d5f7276e.tar.gz
askbot-b4d29815802adb1b01e1c7e3e4c7ad43d5f7276e.tar.bz2
askbot-b4d29815802adb1b01e1c7e3e4c7ad43d5f7276e.zip
temporal commit: added base template and modified askbot.mail.send_mail function to support both html and plain text
-rw-r--r--askbot/mail/__init__.py15
-rw-r--r--askbot/skins/default/templates/email/base_mail.html148
2 files changed, 156 insertions, 7 deletions
diff --git a/askbot/mail/__init__.py b/askbot/mail/__init__.py
index 7ff8a2d3..9002e501 100644
--- a/askbot/mail/__init__.py
+++ b/askbot/mail/__init__.py
@@ -11,6 +11,7 @@ from django.forms import ValidationError
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import string_concat
from django.template import Context
+from django.utils.html import strip_tags
from askbot import exceptions
from askbot import const
from askbot.conf import settings as askbot_settings
@@ -103,14 +104,14 @@ def send_mail(
try:
assert(subject_line is not None)
subject_line = prefix_the_subject_line(subject_line)
- msg = mail.EmailMessage(
- subject_line,
- body_text,
+ msg = mail.EmailMultiAlternatives(
+ subject_line,
+ strip_tags(body_text),
from_email,
recipient_list,
headers = headers
)
- msg.content_subtype = 'html'
+ msg.attach_alternative(body_text, "text/html")
msg.send()
if related_object is not None:
assert(activity_type is not None)
@@ -227,7 +228,7 @@ def bounce_email(
headers = {}
if reply_to:
headers['Reply-To'] = reply_to
-
+
send_mail(
recipient_list = (email,),
subject_line = 'Re: ' + subject,
@@ -284,7 +285,7 @@ def process_parts(parts, reply_code = None):
"""Process parts will upload the attachments and parse out the
body, if body is multipart. Secondly - links to attachments
will be added to the body of the question.
- Returns ready to post body of the message and the list
+ Returns ready to post body of the message and the list
of uploaded files.
"""
body_markdown = ''
@@ -302,7 +303,7 @@ def process_parts(parts, reply_code = None):
stored_files.append(stored_file)
body_markdown += markdown
- #if the response separator is present -
+ #if the response separator is present -
#split the body with it, and discard the "so and so wrote:" part
if reply_code:
signature = extract_user_signature(body_markdown, reply_code)
diff --git a/askbot/skins/default/templates/email/base_mail.html b/askbot/skins/default/templates/email/base_mail.html
new file mode 100644
index 00000000..1a507a64
--- /dev/null
+++ b/askbot/skins/default/templates/email/base_mail.html
@@ -0,0 +1,148 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+ <title>{%block title%}{%endblock%}</title>
+ <style type="text/css">
+ /* Based on The MailChimp Reset INLINE: Yes. */
+ /* Client-specific Styles */
+ #outlook a {padding:0;} /* Force Outlook to provide a "view in browser" menu link. */
+ body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;}
+ /* Prevent Webkit and Windows Mobile platforms from changing default font sizes.*/
+ .ExternalClass {width:100%;} /* Force Hotmail to display emails at full width */
+ .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}
+ /* Forces Hotmail to display normal line spacing. More on that: http://www.emailonacid.com/forum/viewthread/43/ */
+ #backgroundTable {margin:0; padding:0; width:100% !important; line-height: 100% !important;}
+ /* End reset */
+
+ /* Some sensible defaults for images
+ Bring inline: Yes. */
+ img {outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;}
+ a img {border:none;}
+ .image_fix {display:block;}
+
+ /* Yahoo paragraph fix
+ Bring inline: Yes. */
+ p {margin: 1em 0;}
+
+ /* Hotmail header color reset
+ Bring inline: Yes. */
+ h1, h2, h3, h4, h5, h6 {color: black !important;}
+
+ h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: blue !important;}
+
+ h1 a:active, h2 a:active, h3 a:active, h4 a:active, h5 a:active, h6 a:active {
+ color: red !important; /* Preferably not the same color as the normal header link color. There is limited support for psuedo classes in email clients, this was added just for good measure. */
+ }
+
+ h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {
+ color: purple !important; /* Preferably not the same color as the normal header link color. There is limited support for psuedo classes in email clients, this was added just for good measure. */
+ }
+
+ /* Outlook 07, 10 Padding issue fix
+ Bring inline: No.*/
+ table td {border-collapse: collapse;}
+
+ /* Remove spacing around Outlook 07, 10 tables
+ Bring inline: Yes */
+ table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }
+
+ /* Styling your links has become much simpler with the new Yahoo. In fact, it falls in line with the main credo of styling in email and make sure to bring your styles inline. Your link colors will be uniform across clients when brought inline.
+ Bring inline: Yes. */
+ a {color: orange;}
+
+
+ /***************************************************
+ ****************************************************
+ MOBILE TARGETING
+ ****************************************************
+ ***************************************************/
+ @media only screen and (max-device-width: 480px) {
+ /* Part one of controlling phone number linking for mobile. */
+ a[href^="tel"], a[href^="sms"] {
+ text-decoration: none;
+ color: blue; /* or whatever your want */
+ pointer-events: none;
+ cursor: default;
+ }
+
+ .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {
+ text-decoration: default;
+ color: orange !important;
+ pointer-events: auto;
+ cursor: default;
+ }
+
+ }
+
+ /* More Specific Targeting */
+
+ @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
+ /* You guessed it, ipad (tablets, smaller screens, etc) */
+ /* repeating for the ipad */
+ a[href^="tel"], a[href^="sms"] {
+ text-decoration: none;
+ color: blue; /* or whatever your want */
+ pointer-events: none;
+ cursor: default;
+ }
+
+ .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {
+ text-decoration: default;
+ color: orange !important;
+ pointer-events: auto;
+ cursor: default;
+ }
+ }
+
+ @media only screen and (-webkit-min-device-pixel-ratio: 2) {
+ /* Put your iPhone 4g styles in here */
+ }
+
+ /* Android targeting */
+ @media only screen and (-webkit-device-pixel-ratio:.75){
+ /* Put CSS for low density (ldpi) Android layouts in here */
+ }
+ @media only screen and (-webkit-device-pixel-ratio:1){
+ /* Put CSS for medium density (mdpi) Android layouts in here */
+ }
+ @media only screen and (-webkit-device-pixel-ratio:1.5){
+ /* Put CSS for high density (hdpi) Android layouts in here */
+ }
+ /* end Android targeting */
+
+ </style>
+
+ <!-- Targeting Windows Mobile -->
+ <!--[if IEMobile 7]>
+ <style type="text/css">
+
+ </style>
+ <![endif]-->
+
+ <!-- ***********************************************
+ ****************************************************
+ END MOBILE TARGETING
+ ****************************************************
+ ************************************************ -->
+
+ <!--[if gte mso 9]>
+ <style>
+ /* Target Outlook 2007 and 2010 */
+ </style>
+ <![endif]-->
+</head>
+<body>
+<!-- Wrapper/Container Table: Use a wrapper table to control the width and the background color consistently of your email. Use this approach instead of setting attributes on the body tag. -->
+<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable">
+ <tr>
+ <td valign="top">
+ {%block content%}
+ {%endblock%}
+ </td>
+ </tr>
+</table>
+<!-- End of wrapper table -->
+</body>
+</html>