locked
Sending email to Exchange Server RRS feed

  • Question

  • User1314407993 posted

    The web application I'm building currently needs to send emails through the intranet Exchange Server, but I'm getting an error stating that the server is actively refusing my connection. I've checked settings, and they all seem fine. In fact, if I use a Java app to send the email with the exact same information, it goes through just fine. I'm at a loss as to why the emails are not going through.

    string fromEmailAddress = "wsnell@group.domain";
    string toEmailAddress = "wsnell@group.domain";
    string subject = "Test Subject Lin";
    string body = sb.ToString(); // Body of email previously created
    
    MailMessage message = 
       new MailMessage(new MailAddress(fromEmailAddress), 
       new MailAddress (toEmailAddress));
    
    message.Subject = subject;
    message.Body = body;
    message.IsBodyHtml = true;
    
    SmtpClient smtpClient = new SmtpClient();
    smtpClient.Host = "mailhost.group.domain";
    
    try
    {
        smtpClient.Send(message);
    }
    catch (Exception error)
    {
        string errorMessage = error.Message;
    }


     

    Thursday, December 3, 2009 1:09 PM

Answers

  • User1314407993 posted

    I found a fix for my issue, although in truth I only have a hypothesis as to why it worked. First the fix:

    smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

    Anyway, after including this line the emails were sent without problems. I'm thinking that the default delivery method "Network" sends the email directly to the SMTP server, which for some reason it didn't like. The inner exception I was getting said that the server was actively refusing my connection. The PickupDirectoryFromIis leaves the email in a folder specified by IIS where the SMTP server picks up the emails to be sent, so perhaps this was more acceptable for some reason unknown to me.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 4, 2009 3:55 PM