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?
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.
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:
Thanks for all the contributions. They helped get to the bottom of my problem.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.