Unable to send emails to external domain using SMTP
asp.net, email, smtpclient
Solution
I had this issue and authenticating fixed it see below:
SmtpClient client = new SmtpClient(EmailServer, 25);
var SmtpUser = new System.Net.NetworkCredential("domain\\username", "password");
client.Credentials = SmtpUser;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
I had to use the double slash since one slash is the escape character so use two for it to work.
Problem
I am not able to send emails to external domain addresses like 'user.one@asdf.com' using the code below. ``` SmtpClient smtpClient = new SmtpClient(smtpMailServer); smtpClient.UseDefaultCredentials = true; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.EnableSsl = true; //Sending mail. smtpClient.Send(mailMessage); ``` I get an exception - `Mailbox unavailable. The server response was: 5.7.1 Unable to relay for xxx@example.com` If I change the DeliveryMethod to - ``` smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; ``` I am able to send the emails on my local machine. But it fails on the production site with an exception - `Cannot get IIS pickup directory` Can you please suggest me what to do?