aboutsummaryrefslogtreecommitdiffstats
path: root/97suifangqa/apps/sfaccount/functional
diff options
context:
space:
mode:
authorAlvin Li <liweitianux@gmail.com>2013-10-04 23:56:35 +0800
committerAlvin Li <liweitianux@gmail.com>2013-10-04 23:56:35 +0800
commitf552b41f4b337e6844f71c29ff177915abbfa417 (patch)
tree7ade59430c6767a5b379c7a8cb95af3387622b13 /97suifangqa/apps/sfaccount/functional
parent816730ff659e1338ab3e37a1d45ea337e337b3dd (diff)
download97dev-f552b41f4b337e6844f71c29ff177915abbfa417.tar.bz2
* indicator/static/javascripts/card_chart.js:
improved the display position of 'detail_card_info' * indicator/templates/indicator/SheetDefault.html: destroy 'qtip' when close card * added new app 'apps/sfaccount' * implemented 'signup' and 'activate' functions * implemented async sending activation mail (using 'django-celery' and 'redis') * moved 'registration/*' templates to 'sfaccount/templates' * implemented 'password_change' function: o password_change o password_change_done * implemented 'password_reset' function o password_reset o password_reset_done o password_reset_confirm o password_reset_complete o re-write 'sfaccount.fomrs.SFPasswordResetForm' o re-write 'sfaccount.views.password_reset_view' * improved 'sfaccount.functional' send mail functions o to send 'multipart' mail * added 'README.txt' * added app 'apps/recommend': for comparing with the SCI papers and then recommending most related papers for user.
Diffstat (limited to '97suifangqa/apps/sfaccount/functional')
-rw-r--r--97suifangqa/apps/sfaccount/functional/__init__.py21
-rw-r--r--97suifangqa/apps/sfaccount/functional/mail.py45
2 files changed, 66 insertions, 0 deletions
diff --git a/97suifangqa/apps/sfaccount/functional/__init__.py b/97suifangqa/apps/sfaccount/functional/__init__.py
new file mode 100644
index 0000000..6cfbcbf
--- /dev/null
+++ b/97suifangqa/apps/sfaccount/functional/__init__.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+
+from django.conf import settings
+from sfaccount.functional.mail import send_mail_multipart
+
+EMAIL = settings.SF_EMAIL
+
+def send_mail(to, subject, content_text=None, content_html=None):
+ send_mail_multipart(
+ host=EMAIL['smtp_host'],
+ port=EMAIL['smtp_port'],
+ username=EMAIL['username'],
+ password=EMAIL['password'],
+ mail_from=EMAIL['from'],
+ mail_to=to,
+ subject=subject,
+ content_text=content_text,
+ content_html=content_html,
+ display_from=EMAIL['display_from']
+ )
+
diff --git a/97suifangqa/apps/sfaccount/functional/mail.py b/97suifangqa/apps/sfaccount/functional/mail.py
new file mode 100644
index 0000000..30b1701
--- /dev/null
+++ b/97suifangqa/apps/sfaccount/functional/mail.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+
+import smtplib
+
+from email.mime.text import MIMEText
+from email.mime.multipart import MIMEMultipart
+
+
+def send_mail_multipart(host,
+ port,
+ username,
+ password,
+ mail_from,
+ mail_to,
+ subject,
+ content_text=None,
+ content_html=None,
+ display_from=None):
+ # create message container
+ # correct MIME type is 'multipart/alternative'
+ msg = MIMEMultipart('alternative')
+ # from & to
+ msg['From'] = display_from or mail_from
+ if isinstance(mail_to, (list, tuple)):
+ msg['To'] = ', '.join(mail_to)
+ else:
+ msg['To'] = mail_to
+ # subject
+ msg['Subject'] = subject
+ # body (utf-8 encode required)
+ if isinstance(content_text, unicode):
+ content_text = content_text.encode('utf-8')
+ if isinstance(content_html, unicode):
+ content_html = content_html.encode('utf-8')
+ text_part = MIMEText(content_text, 'plain')
+ html_part = MIMEText(content_html, 'html')
+ msg.attach(text_part)
+ msg.attach(html_part)
+ # send
+ s = smtplib.SMTP()
+ s.connect(host, port)
+ s.login(username, password)
+ s.sendmail(mail_from, mail_to, msg.as_string())
+ s.quit()
+