BURO #79 xxd

February 28, 2008

Django Newsletter

Filed under: Django — xxd @ 10:47 am

There is a simple example from http://www.rossp.org/blog/2006/jul/11/sending-e-mails-templates/
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

Powered by ScribeFire.

2 Comments »

  1. This is the first time I comment here and I must say that you give us genuine, and quality information for bloggers! Good job.
    p.s. You have an awesome template for your blog. Where did you find it?

    Comment by hydraulic floor jacks — March 14, 2009 @ 12:41 pm | Reply

  2. Great stuff here 🙂

    Comment by grants 360 kit — February 2, 2010 @ 6:47 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.