Django Sendmail

219 views
Skip to first unread message

xuexia...@gmail.com

unread,
Feb 20, 2008, 12:20:31 PM2/20/08
to Django users
Hi everyone:
I am currently testing my Sendmail code on a local machine (on
localhost), which is similar to djangobook chapter 14: other
contributed sub-frameworks, the codes are below:

python manage shell

from django.contrib.auth.models import User
email = ' xuexia...@gmail.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 Site
current_site = Site.objects.get_current()
send_mail('Thanks for subscribing to %s alerts' % current_site.name,
'Thanks for your subscription. We appreciate it.\n\n-The %s team.' %
current_site.name, 'editor@%s' % current_site.domain,
[new_user.email])

However, i had some error message as below:
Traceback (most recent call last):
File "<console>", line 1, in <module>
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')

it's about the smtp server or it's can not run on a local machine?

Thanks a lot

Dong

Brian Morton

unread,
Feb 20, 2008, 3:03:16 PM2/20/08
to Django users
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.

On Feb 20, 12:20 pm, "xuexiaodon...@gmail.com"
<xuexiaodon...@gmail.com> wrote:
> Hi everyone:
> I am currently testing my Sendmail code on a local machine (on
> localhost), which is similar to djangobook chapter 14: other
> contributed sub-frameworks, the codes are below:
>
> python manage shell
>
> from django.contrib.auth.models import User
> email = ' xuexiaodon...@gmail.com'

xuexia...@gmail.com

unread,
Feb 21, 2008, 6:43:05 AM2/21/08
to Django users
Thanks Brian
Reply all
Reply to author
Forward
0 new messages