sending email using localhost (mac os x)

976 views
Skip to first unread message

omat

unread,
Mar 18, 2008, 7:10:41 AM3/18/08
to Django users
Hi,

I am on Mac OS X Leopard and can send mail without any trouble from
within shell via sendmail like that:

$ sendmail m...@my.com
some
text
.
$

Doesn't that mean that I have a local mail server can send mail with
django's send_mail with the default server settings? (i.e. with empty
EMAIL_HOST, EMAIL_HOST_USER and EMAIL_HOST_PASSWORD)


Thanks,
oMat

omat

unread,
Mar 18, 2008, 8:12:14 AM3/18/08
to Django users
Instead I get "Can't assign requested address":


Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.5/site-packages/django/core/mail.py", line
326, in send_mail
return EmailMessage(subject, message, from_email, recipient_list,
connection=connection).send()
File "/Library/Python/2.5/site-packages/django/core/mail.py", line
255, in send
return self.get_connection(fail_silently).send_messages([self])
File "/Library/Python/2.5/site-packages/django/core/mail.py", line
157, in send_messages
new_conn_created = self.open()
File "/Library/Python/2.5/site-packages/django/core/mail.py", line
122, in open
self.connection = smtplib.SMTP(self.host, self.port)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/smtplib.py", line 244, in __init__
(code, msg) = self.connect(host, port)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/smtplib.py", line 310, in connect
raise socket.error, msg
error: (49, "Can't assign requested address")


Thanks...

Michael Wieher

unread,
Mar 18, 2008, 10:13:18 AM3/18/08
to django...@googlegroups.com
Looks like the host/port is incorrect.  I'd double-check that its set correctly (or to localhost/127.0.0.1) and that your machine has whichever port its trying to connect to open & available.

2008/3/18, omat <om...@gezgin.com>:

omat

unread,
Mar 18, 2008, 11:48:07 AM3/18/08
to Django users
Thanks for the reply.

$ python manage.py shell
>>> settings.EMAIL_HOST
'localhost'
>>> settings.EMAIL_PORT
25
>>> send_mail('test', 'message', 'omat', ['om...@gezgin.com'])

and I get the Traceback above.

When I set the host to '127.0.0.1' instead of 'localhost', I get a
"connection refused" error.


Thanks,
omat



On Mar 18, 4:13 pm, "Michael Wieher" <michael.wie...@gmail.com> wrote:
> Looks like the host/port is incorrect. I'd double-check that its set
> correctly (or to localhost/127.0.0.1) and that your machine has whichever
> port its trying to connect to open & available.
>
> 2008/3/18, omat <o...@gezgin.com>:

Evert Rol

unread,
Mar 18, 2008, 1:25:46 PM3/18/08
to django...@googlegroups.com
> Thanks for the reply.
>
> $ python manage.py shell
>>>> settings.EMAIL_HOST
> 'localhost'
>>>> settings.EMAIL_PORT
> 25
>>>> send_mail('test', 'message', 'omat', ['om...@gezgin.com'])
>
> and I get the Traceback above.
>
> When I set the host to '127.0.0.1' instead of 'localhost', I get a
> "connection refused" error.


Check what your sendmail settings are; maybe these are different. I
think the configuration is in '/private/etc/postfix/main.cf' on Leopard.
I'm not familiar with sendmail, so the real settings may even be
buried deeper somewhere else, but afaik, sendmail isn't configured
properly to send email on a default setup. So something in your setup
allows you to send email through sendmail, while preventing sending
directly through smtp (possibly, sendmail does use another smtp
server, not localhost).

>> Looks like the host/port is incorrect. I'd double-check that its set
>> correctly (or to localhost/127.0.0.1) and that your machine has
>> whichever
>> port its trying to connect to open & available.
>>

David Reynolds

unread,
Mar 20, 2008, 8:47:59 AM3/20/08
to django...@googlegroups.com

On 18 Mar 2008, at 3:48 pm, omat wrote:
> When I set the host to '127.0.0.1' instead of 'localhost', I get a
> "connection refused" error.
>
>
> Thanks,
> omat

I don't think the MTA is running by default on OS X (certainly not on
Tiger, not sure about Leopard)

ISTR you can just do sudo postfix start or use something like Postfix
enabler [0]

Alternatively set EMAIL_HOST to your ISP's SMTP server.

0 - http://cutedgesystems.com/software/PostfixEnabler/
--
David Reynolds
da...@reynoldsfamily.org.uk


Reply all
Reply to author
Forward
0 new messages