Search code examples
c#smtpsmtpclient

C# Smtp.Send not working for specific email address


I haven't had any problems with this code except for one user's email address (everyone has the same "@OurCompany" domain name).

I have sent an email to him through Outlook and it went through fine. There are no exceptions being thrown when the code is run, but our SysAdmin says the emails I tried to send aren't even hitting email the server.

public static void SendEmail(string sTo, string sSubject, string sBody)
{
    using (MailMessage message = new MailMessage(new MailAddress(ConfigurationManager.AppSettings["FromUser"], "User"), new MailAddress(sTo))
    {
        Subject = sSubject,
        Body = sBody
    })
    {
        using (var client = new SmtpClient(ConfigurationManager.AppSettings["SMTPGridName"]))
        {
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Port = int.Parse(ConfigurationManager.AppSettings["SmtpPort"]);
            client.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["EmailCredential"],
                ConfigurationManager.AppSettings["EmailPassword"]);
            client.EnableSsl = true;
            client.Send(message);
        }
    }
}

Solution

  • It turned out the emails were being dropped by SendGrid before it got to our email server for reason "Bounced Address." The SysAdmin thinks the email server might have been down at one point which caused the email address to be added to a "does not exist" list. The address was removed from the list and it works now.

    Thanks for the suggestions