smtplib problem, Unable to relay for

B

Benedict Verheyen

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("(e-mail address removed)", ["(e-mail address removed)"], 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: {'(e-mail address removed)': (550, '5.7.1
Unable to relay for (e-mail address removed)')}

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?

Thanks
Benedict
 
G

Grant Edwards

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("(e-mail address removed)", ["(e-mail address removed)"], 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: {'(e-mail address removed)': (550, '5.7.1
Unable to relay for (e-mail address removed)')}

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.
 
D

Dennis Lee Bieber

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.

Alternatively, if the firewall/ISP doesn't block passthrough SMTP,
you don't relay, but code to connect directly to the /recipient's/ mail
server (which may need nameserver MX-record look-ups for each
recipient). Rather than connect to your local mail server and ask it to
send to all the addresses, you'd maybe sort the addresses by recipient
server, connect to those machines (in sequence), and send only mail
destined to each host.

Such a host should be willing to accept mail destined for a "local"
(to it) recipient.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top