Mailbox unavailable. The server response was: 5.7.1 Unable to relay


I'm attempting to send an email to an external address through a sharepoint application page. I can send an email internally with no problem, but when I attempt to send externally on port 25, I receive the following error:

Mailbox unavailable. The server response was: 5.7.1 Unable to relay

if I try sending through port 587 I receive the following error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated

Here's my code:

using (MailMessage message = new MailMessage(fromadd, toadd))
    SmtpClient client = new SmtpClient(smtpserver, port);
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential(networkuser, password);
    client.DeliveryMethod = SmtpDeliveryMethod.Network;

    message.Subject = "test";
    message.Body = "test";

    message.CC.Add(new MailAddress(""));


I've tried running the same code from a console appl off of my sharepoint box and it works perfectly. it seems as if from sharepoint to the smtp server the network credentials are being lost.  

my sharepoint server's outgoing email settings are configured using the same smtp server and same user account and this works as expected.

does anyone have an idea of what I could be doing wrong here?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
I believe what you need to do is add the IP address to the relay list.  Go to your SMTP properties and on the relay tab, add the IP of the Exchange server.  Also look at following link:
martushaProduct managerCommented:
1) Go to Administrative Tools -> IIS 6.0 Manager
2) Right click "SMTP Virtual Server" then Click Properties
3) Select Access tab
4) Click "Relay..." in Relay Restrictions
5) Select "Only the list below"
6) Add and your server IP to the list
7) Check Allow all computers which successfully authenticate to relay, regardless of the list above
8) Click "OK"
telliot79Author Commented:
This EE post helped me get to the bottom of my problem:

With this comment:

"SharePoint sends outgoing email as anonymous SMTP.   All you have to do is to allow the SharePoint server IP as an allowed relay under the SMTP virtual server."

Unfortunately we can't send emails anonymously. So I configured SMTP on my WFE server following this guide:

I then performed the following:
Open IIS 6.0 Manager
Right Click SMTP Virtual Server and click properties
select "Only the list below" and add my SP WFE server.
Delivery Tab
Outbound Security
Select Integrated Windows Authentication and type in my user that will send emails. Click OK.
Still on the delivery Tab > Advanced
Type my exchange smtp server as the Smart Host.
Restart SMTP server.

Then used this SMTP server to relay the emails.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
telliot79Author Commented:
Thanks for all the contributions. They helped get to the bottom of my problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.