smtplib problem, Unable to relay for

Grant Edwards grante at visi.com
Sat Dec 22 10:12:16 EST 2007


On 2007-12-21, Benedict Verheyen <benedict.verheyen at gmail.com> wrote:

> i get an "Unable to relay for" when trying to send an email
> from within my network to an email address not on my domain. I
> don't understand why it says "relaying" as i'm sending from an
> internal domain user to an external user.

You're asking the SMTP server to accept mail for a user that's
not local to that server.  That's relaying.

> Email server is exchange 2003

Ah, well, that's too bad.  You can probably get it to work
anyway...

> See this trace
>
> >>> smtp.sendmail("info at mydomain.be", ["user at externaldomain.com"], msg)
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>    File "C:\Python25\Lib\smtplib.py", line 695, in sendmail
>      raise SMTPRecipientsRefused(senderrs)
> smtplib.SMTPRecipientsRefused: {'user at externaldomain.com': (550, '5.7.1 
> Unable to relay for user at externaldomain.com')}
>
> The smpt var is this:
> smtp = smtplib.SMTP(server) where server is my mail server
>
> I can mail to any user that is part of mydomain.be but as soon
> as i try an external address, i get the "Unable to relay"
> message.
>
> With a mail program it works

With what "mail program"?  Outlook?  Outlook doesn't use SMTP
to send mail, so it doesn't matter what works or doesn't work
in Outlook. If relaying does work with other SMTP clients, then
comparing a TCP trace of a program that works with one from a
program that doesn't work would be very informative.

> but i need to be able to do it via code.

You can use Python to send e-mails via Outlook if you want to
do that instead of using SMTP.  However, Microsoft has crippled
Outlook's automation interface in a half-witted and mostly
ineffectual attempt to plug security holes.  So, you have to
jump through a hoop to bypass Microsoft Outlook's security
stuff (it's not really hard to bypass -- big surprise there).
Googling for "python sending mail with outlook" will find you
all sorts of examples.

> I thought that i would have to authenticate (smtp.login) to
> our mail server but that didn't resolve the issue
>
> Any idea how i could do this?

Ask the Exchange admin to enable relaying.  But, (this is
_very_important_) make sure he limits relaying so that it only
relays mail accepted from the _internal_ network.  If you
allowing relaying of mail accepted from outside hosts (to
outside hosts), you'll be used by spammers and criminals for
all sorts of evil, mischief, and crime.

-- 
Grant Edwards                   grante             Yow!  I'm rated PG-34!!
                                  at               
                               visi.com            



More information about the Python-list mailing list