smtplib problem, Unable to relay for

Tim Williams tdwdotnet at gmail.com
Fri Dec 21 21:05:37 EST 2007


On 21/12/2007, Benedict Verheyen <benedict.verheyen at gmail.com> wrote:
> Hi,
>
> 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.
> Email server is exchange 2003
>
> 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 but i need to be able to do it via code.
> 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?

Have you asked your Exchange admin if the server is allowed to relay via SMTP?

The Exchange server is returning a valid response so it's most likely
that it is just not configured to relay (via SMTP).

If your "working mail program" is Outlook then it is using MAPI not
SMTP to send/receive email.

If your "working mail program" is an SMTP email client, or you have
added a POP3/IMAP & SMTP account to your Outlook, then something
strange is happening and relaying is probably allowed. You would need
to talk to your exchange admin to see what's shown in the server logs
for your failed SMTPLIB attempts.

HTH :)



More information about the Python-list mailing list