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";
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?