You are not logged in.

#1 2007-01-05 10:36:02

remi
Member
From: London
Registered: 2006-09-19
Posts: 741
Website

Sending e-mails from Django

baxter wrote:

As you may recall, I was having trouble getting Django to send its email error messages. I knew that you can't use Django's default localhost email server, but still couldn't make it work. With a little help from Jeff Croft, I've figured it out, and thought I'd pass it on.

In the Django settings file, the relevant settings are:
EMAIL_HOST='mailN.webfaction.com'
EMAIL_HOST_USER='baxter'
EMAIL_HOST_PASSWORD='xxxxxx'
EMAIL_PORT='25'
DEFAULT_FROM_EMAIL = "admin@domain.com"
SERVER_EMAIL = "admin@domain.com"

Out of those, you probably DON'T need EMAIL_PORT, since Django defaults to 25 anyway. But the real key is DEFAULT_FROM_EMAIL or (more likely) SERVER_EMAIL. Once those were in place, it worked. It looks like the mail server won't send it through without a sender.

Thanks for the tip.

Remi.


WebFaction - Smarter web hosting

Offline

 

#2 2007-11-08 19:45:21

swanznito
Member
Registered: 2007-11-08
Posts: 3

Re: Sending e-mails from Django

Hey I have tried to do that but it still gives me the same error. I am not trying to get django error emails, but rather I want to send an email using the django send_mail function.

SMTPAuthenticationError at /getinfo/
(535, '5.7.0 authentication failed')

these are my settings:
EMAIL_HOST = 'mail3.webfaction.com'
EMAIL_HOST_USER = 'swanznito'
EMAIL_HOST_PASSWORD = '******'
EMAIL_PORT = '25'
DEFAULT_FROM_EMAIL = "swanznito@mydomain.com"
SERVER_EMAIL = "swanznito@mydomain.com"

is there a particular mailbox that the DEFAULT_FROM_EMAIL and SERVER_EMAIL have to be?

any other ideas?

Offline

 

#3 2007-11-08 19:53:55

fogleman
Member
Registered: 2007-10-22
Posts: 12

Re: Sending e-mails from Django

I have EMAIL_PORT = 25 (integer, not a string) in my settings.  Not sure if that's the problem.

Offline

 

#4 2007-11-08 19:58:38

swanznito
Member
Registered: 2007-11-08
Posts: 3

Re: Sending e-mails from Django

fogleman wrote:

I have EMAIL_PORT = 25 (integer, not a string) in my settings.  Not sure if that's the problem.

thanks for the quick reply but yea that still didn't work.

Offline

 

#5 2007-11-08 21:03:24

IAIHMB
Member
From: Hudson, Florida.
Registered: 2006-09-19
Posts: 1362

Re: Sending e-mails from Django

Assuming your control panel and forum usernames are the same this is your problem:

EMAIL_HOST = 'mail3.webfaction.com'

You're on Mail 4. smile


-David Sissitka

Offline

 

#6 2007-11-08 21:14:21

swanznito
Member
Registered: 2007-11-08
Posts: 3

Re: Sending e-mails from Django

haha! it worked. thanks iaihmb. youre a lifesaver

Offline

 

#7 2007-12-28 18:39:52

dkiesow
Member
Registered: 2007-12-10
Posts: 19

Re: Sending e-mails from Django

I am having no luck with this - trying to send the Django broken_link emails.

Settings.py:

EMAIL_HOST = 'mail4.webfaction.com'
EMAIL_HOST_USER= 'dkiesow'
EMAIL_FROM = "damon@kiesow.net"
EMAIL_HOST_PASSWORD= '******'
EMAIL_PORT= '25'
SEND_BROKEN_LINK_EMAILS = True
DEFAULT_FROM_EMAIL = "damon@kiesow.net"
SERVER_MAIL= "damon@kiesow.net"

Any suggestions?

Offline

 

#8 2007-12-30 09:29:43

remi
Member
From: London
Registered: 2006-09-19
Posts: 741
Website

Re: Sending e-mails from Django

dkiesow wrote:

I am having no luck with this - trying to send the Django broken_link emails.

Settings.py:

EMAIL_HOST = 'mail4.webfaction.com'
EMAIL_HOST_USER= 'dkiesow'
EMAIL_FROM = "damon@kiesow.net"
EMAIL_HOST_PASSWORD= '******'
EMAIL_PORT= '25'
SEND_BROKEN_LINK_EMAILS = True
DEFAULT_FROM_EMAIL = "damon@kiesow.net"
SERVER_MAIL= "damon@kiesow.net"

Any suggestions?

Assuming your password is correct then your settings look OK... Do you get any useful error message in your logs?


Remi.


WebFaction - Smarter web hosting

Offline

 

#9 2007-12-30 16:11:18

dkiesow
Member
Registered: 2007-12-10
Posts: 19

Re: Sending e-mails from Django

Nope - nothing showing in any error logs.

Offline

 

#10 2007-12-30 22:18:01

mae
Member
Registered: 2006-10-14
Posts: 445

Re: Sending e-mails from Django

I have always found this a little annoying, almost everything that is installed in webfaction needs to be magled to use the external mail server. why can't you guys enable the local sendmail for apps to send out notifications? I have seen this happen with trac, wordpress and drupal.

Offline

 

#11 2007-12-31 05:14:44

remi
Member
From: London
Registered: 2006-09-19
Posts: 741
Website

Re: Sending e-mails from Django

dkiesow wrote:

Nope - nothing showing in any error logs.

Can you try your settings in a "manual" script (such as the one at http://blog.webfaction.com/email-faq#send ) and see if they work?


Remi.


WebFaction - Smarter web hosting

Offline

 

#12 2007-12-31 05:19:40

remi
Member
From: London
Registered: 2006-09-19
Posts: 741
Website

Re: Sending e-mails from Django

mae wrote:

I have always found this a little annoying, almost everything that is installed in webfaction needs to be magled to use the external mail server. why can't you guys enable the local sendmail for apps to send out notifications? I have seen this happen with trac, wordpress and drupal.

There a few reasons for doing it that way:

- performance: we feel like e-mail traffic shouldn't impact websites

- monitoring: people can do a lot of bad things with an SMTP server so we want to monitor what's happening (make sure nobody is sending spam for instance). Having only a few dedicated SMTP servers makes this a lot easier

It's true that a few tools don't support external SMTP servers with authentication our of the box but this is becoming less and less frequent because most new tools or new versions of existing tools do support it.

Cheers,

Remi.


WebFaction - Smarter web hosting

Offline

 

#13 2007-12-31 18:17:14

dkiesow
Member
Registered: 2007-12-10
Posts: 19

Re: Sending e-mails from Django

Yes - the test script works- but still no luck from with Django.

Offline

 

#14 2007-12-31 20:28:29

IAIHMB
Member
From: Hudson, Florida.
Registered: 2006-09-19
Posts: 1362

Re: Sending e-mails from Django

I believe that that this is your problem:

SEND_BROKEN_LINK_EMAILS = 'True'

SEND_BROKEN_LINK_EMAILS needs to be set to True, not 'True'.

Django can send e-mail, see:

[dkiesow@web23 banjo]$ python2.5 manage.py shell
Python 2.5.1 (r251, Nov  9 2007, 22:28:58)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.mail import send_mail
>>> send_mail('Test', 'Test', 'damon@kiesow.net', ['david@webfaction.com'])
1
>>>
[dkiesow@web23 banjo]$

Hope it helps. smile


-David Sissitka

Offline

 

#15 2007-12-31 20:45:30

dkiesow
Member
Registered: 2007-12-10
Posts: 19

Re: Sending e-mails from Django

Thanks for catching those quotes. I had gone over that specific issue several times - but missed that one apparently.

But, still no luck on the email. I must have something else wrong in the code - it is obviously not Django or your email server that is the problem.

thanks

Damon

Offline

 

#16 2007-12-31 21:29:11

dkiesow
Member
Registered: 2007-12-10
Posts: 19

Re: Sending e-mails from Django

Actually - I am now getting an error in the logs:

SMTPSenderRefused: (553, '5.5.4 <root@localhost>... Real domain name required for sender address', 'root@localhost'), referer:

Will try to track this down, but not sure why it is not recognizing the settings.py directives.

Offline

 

#17 2007-12-31 22:24:34

dkiesow
Member
Registered: 2007-12-10
Posts: 19

Re: Sending e-mails from Django

Found the problem -

Along with the ' around True I also had SERVER_EMAIL typed as SERVER_MAIL

So - working now.

thanks

Damon

Last edited by dkiesow (2007-12-31 22:30:22)

Offline

 

#18 2008-03-09 23:23:04

jhickner
Member
Registered: 2008-03-09
Posts: 2

Re: Sending e-mails from Django

IAIHMB wrote:

[dkiesow@web23 banjo]$ python2.5 manage.py shell
Python 2.5.1 (r251, Nov  9 2007, 22:28:58)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.mail import send_mail
>>> send_mail('Test', 'Test', 'damon@kiesow.net', ['david@webfaction.com'])
1
>>>
[dkiesow@web23 banjo]$

Hi, I've been running into some email issues and ran across this thread. When I try the exact same thing you're doing above, I get an error at the point where I try to import send_mail:

[knoxvoice@web31 knoxvoice]$ python2.5 manage.py shell
Python 2.5.1 (r251, Feb 27 2008, 16:29:04)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.mail import send_mail
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/knoxvoice/lib/python2.5/django/core/mail.py", line 4, in <module>
    from email.MIMEText import MIMEText
  File "/home/knoxvoice/webapps/django/knoxvoice/email.py", line 3, in <module>
    import smtplib
  File "/usr/local/lib/python2.5/smtplib.py", line 46, in <module>
    import email.Utils
ImportError: No module named Utils
>>>

Any idea what might be happening? This is a brand new account.

- Jason

Offline

 

#19 2008-03-10 09:30:46

IAIHMB
Member
From: Hudson, Florida.
Registered: 2006-09-19
Posts: 1362

Re: Sending e-mails from Django

I believe that the problem is that ~/webapps/django/knoxvoice/ is on your PYTHONPATH and ~/webapps/django/knoxvoice/email.py has taken precedence over the e-mail module in Python's standard library. In other words, try renaming your e-mail.py. smile


-David Sissitka

Offline

 

#20 2008-03-10 12:04:06

jhickner
Member
Registered: 2008-03-09
Posts: 2

Re: Sending e-mails from Django

That did the trick. Thanks!

Offline

 

#21 2008-05-27 15:14:04

stranger1
Member
Registered: 2008-03-02
Posts: 19

Re: Sending e-mails from Django

I am using the GMAIL SMTP server for this purpose and it works... If you need help configuring with Gmail I can help...

Offline

 

#22 2008-05-27 17:16:41

patrickbeeson
Member
From: Knoxville, TN
Registered: 2007-05-17
Posts: 10
Website

Re: Sending e-mails from Django

I'm unable to get error emails using the following:

EMAIL_HOST = 'mail5.webfaction.com'
EMAIL_HOST_USER = 'pbeeson'
EMAIL_HOST_PASSWORD = '********'
DEFAULT_FROM_EMAIL = 'noreply@knoxd.com'
SEND_BROKEN_LINK_EMAILS = True
SERVER_EMAIL = 'patrick@knoxd.com'
EMAIL_PORT = 25

I can however receive emails sent using my site's contact form to the admins listed in the settings.py (using smtp). Any help would be appreciated!

Offline

 

#23 2008-05-27 17:45:45

stranger1
Member
Registered: 2008-03-02
Posts: 19

Re: Sending e-mails from Django

Hey patrick, did u try sending mail using the commandprompt.

>>> from django.core.mail import send_mail
>>> send_mail('Test', 'Test', 'damon@kiesow.net', ['david@webfaction.com'])
1

You may find some useful error information if you do that.

Last edited by stranger1 (2008-05-27 17:46:02)

Offline

 

#24 2008-05-27 18:11:22

patrickbeeson
Member
From: Knoxville, TN
Registered: 2007-05-17
Posts: 10
Website

Re: Sending e-mails from Django

I did, and I get the following traceback:

>>> from django.core.mail import send_mail
>>> send_mail('Test', 'Test', 'patrick@knoxd.com', ['patrick@patrickbeeson.com'])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/pbeeson/webapps/django/lib/django/core/mail.py", line 333, in send_mail
    connection=connection).send()
  File "/home/pbeeson/webapps/django/lib/django/core/mail.py", line 259, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/pbeeson/webapps/django/lib/django/core/mail.py", line 162, in send_messages
    new_conn_created = self.open()
  File "/home/pbeeson/webapps/django/lib/django/core/mail.py", line 127, in open
    local_hostname=DNS_NAME.get_fqdn())
  File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python2.5/smtplib.py", line 310, in connect
    raise socket.error, msg
error: (111, 'Connection refused')

Also, when I use "mail5.webfaction.com" instead of "smtp5.webfaction.com" I can't use my site's contact form.

Offline

 

#25 2008-05-28 12:19:19

likebike
Member
Registered: 2008-05-04
Posts: 263

Re: Sending e-mails from Django

The SMTP servers require authentication. Here is the function signature of send_mail:

send_mail(subject, message, from_email, recipient_list,
fail_silently=False, auth_user=None,
auth_password=None)


... Try specifying auth_user and auth_password.

Regards,

~Chris Sebastian

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson