locked
Mail goes to more than 1 time. RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    I am sending mail using c# code. See the code below

            string strBody = Emailbody;
            Msg.Body = strBody;
            Msg.Priority = MailPriority.Normal;
            SmtpClient client = new SmtpClient("smtp.office365.com");
            client.Port = 587;
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            NetworkCredential cred = new System.Net.NetworkCredential("xxxxx@xxxxxx.xxxx", "*******");
            client.Credentials = cred;
            try
            {
                client.Send(Msg);
    
            }
            catch (Exception ex)
            {
    
                // Response.Write("Send failure: " + ex.ToString());
            }

    Code works fine but It throw same mail 5-6 times.

    Then I changed the code like below.

            string strBody = Emailbody;
            Msg.Body = strBody;
            Msg.Priority = MailPriority.Normal;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "xxx.xxx.x.x"; // some IP
            try
            {
                smtp.Send(Msg);   
            }
            catch (Exception ex)
            {
    
                // Response.Write("Send failure: " + ex.ToString());
            }

    This also works fine and send mail only for once.

    What is the issue with the first code using smtp client (smtp.office365.com)?

    Thanks

    Thursday, November 10, 2016 7:09 AM

Answers

  • User-2057865890 posted

    Hi Demoninside9,

    Not a code issue. It may be caused by SMTP server.

    "There is a point in the process of delivering a message where the receiving mailer knows it has accepted the message but the sending mailer is still not sure the message has been reliably delivered. If the SMTP conversation is broken at this point, the sending mailer will be forced to re-deliver the message, even though the message has already been received and delivered by the receiving mailer."

    reference: https://tools.ietf.org/html/rfc1047 

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 11, 2016 4:48 AM