Django Newsletter

In templates directory, create email.txt as below:

Dear {{ name }},Thank you for signing up with {{ product_name }}. Your new username is {{ username }}, and you can login at {{ login_url }}. Once logged in, you'll be able to access more features on our website. We hope that {{ product_name }} is of good use to you. If you have any feedback, please respond to this e-mail or submit it to us via our website.Regards,{{ product_name }} Administration{{ product_url }}

the send mail function:

from django.template import loader,
Contextt = loader.get_template('registration/email.txt')
c = Context({ 'name': new_data['first_name'], 'product_name':
'Your Product Name',
'product_url': 'http://www.yourproject.com/',
'login_url': 'http://www.yourproject.com/login/',
'username': new_data['username'],})

from django.core.mail import send_mailsend_mail
('Welcome to My Project', t.render(c), 'from@address.com', [new_data['email']], fail_silently=False)

the user will be receiving like this:

Dear Ross,Thank you for signing up with Your Product Name.Your new username is rossp, and you can login at http://www.yourproject.com/login/. Once logged in, you'll be able to access more features on our website..We hope that Your Product Name is of good use to you. If you have any feedback, please respond to this e-mail or submit it to us via our website.Regards,Your Product Name Administrationhttp://www.yourproject.com/

The following code logs into an account, retrieves a list of
threads, displays information about them and displays the source of the
individual messages.

import libgmail
ga = libgmail.GmailAccount(”google@gmail.com”, “mymailismypass”)
ga.login()
folder = ga.getMessagesByFolder(’inbox’)
for thread in folder:

print thread.id, len(thread), thread.subject
for msg in thread:
print ” “, msg.id, msg.number, msg.subject
print msg.source#can not send mail out:By default, Django assumes that the SMTP server is running locally.

If you don’t have one running locally, you need to set EMAIL_HOST and
EMAIL_PORT in your settings.py file to a valid SMTP server.
EMAIL_HOST = “mailhost.company.com” (http://groups.google.com/group/django-users/browse_thread/thread/e2e5da1a395bbaa5/22c13145abf042a0?hl=en#22c13145abf042a0)

#Je suis en train de faire un project pour envoyer email sur
Django, je utilise le send_mail function de Python, mais il y a une
erreur (Je t’ai envoyee par email), je dois setup le SMPT serveur sur
mon ordinadeur?

from django.contrib.auth.models import User
email = ’something@hotmail.com’
username = ‘xiaodong’
password = ‘xiaodong’
new_user = User.objects.create_user(username, password, email)
new_user.save()
from django.core.mail import send_mail
from django.contrib.sites.models import Sitecurrent_site = Site.objects.get_current()
send_mail(’Thanks for subscribing to %s alerts’ % current_site.name, ‘Thanks for your subscription. We appreciate it.nn-The %s team.% current_site.name, ‘editor@%s’ % current_site.domain, [new_user.email])

Traceback (most recent call last):
File “”, line 1, in
File “/usr/lib/python2.5/site-packages/django/core/mail.py”, line 49, in send_mail
return send_mass_mail([[subject, message, from_email, recipient_list]], fail_silently, auth_user, auth_password)
File “/usr/lib/python2.5/site-packages/django/core/mail.py”, line 66, in send_mass_mail
server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
File “smtplib.py”, line 244, in __init__
(code, msg) = self.connect(host, port)
File “smtplib.py”, line 310, in connect
raise socket.error, msg
error: (111, ‘Connection refused’)

This is *probably* a bug in python-libgmail, which should be fixed in 0.1.6.1 (Gutsy has 0.1.5.1, latest version is not 0.1.7)
http://sourceforge.net/project/downloading.php?group_id=113492&use_mirror=kent&filename=libgmail-0.1.8.tar.gz&8221181

http://libgmail.sourceforge.net/
libgmail — Python binding for Google’s Gmail service

Reference:
http://www.b-list.org/weblog/2006/sep/02/django-tips-user-registration/
http://www.stonemind.net/blog/2007/04/13/django-registration-for-newbies/
Python code:
Multi-attachment: http://code.djangoproject.com/ticket/1541
Python SendMail: http://gelb.bcom.at/trac/simplemail/browser/trunk/simplemail.py
Send HTML Mail: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/67083

posted @   xxd  阅读(426)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示