I'm trying to send an email to an external address as part of a web app. I can send an email fine when using a simple executable running on the server:
private void button1_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage(welcomeMessageFrom, toAddress, welcomeMessageSubject, welcomeMessageSubject);
SmtpClient emailClient = new SmtpClient("mail.sortuv.com");
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(username, password);
emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
emailClient.Send(message);
}
However, trying the same code from an ASP.NET page gives the following exception:
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for <user's email>
I'm new to IIS but do you have suggestions on how to debug?
UPDATE: I had to specify the domain for the user as well. Still not sure why a regular .exe was ok without it. Hope this helps someone.