none
I define a class to send the website's error to my email account,but why can't i get the message? RRS feed

  • Question

  • public static void SendMail(string from, string to, string subject, string body)
        {
            SmtpClient mailClient = new SmtpClient(BallonShopConfiguration.MailServer);
            mailClient.Credentials = new NetworkCredential(BallonShopConfiguration.MailUsername, BallonShopConfiguration.MailPassword);
            MailMessage mailMessage = new MailMessage(from, to, subject, body);
            mailClient.Send(mailMessage);
        }

        public static void LogError(Exception ex)
        {
            string dataTime = DateTime.Now.ToLongDateString() + ",at" + DateTime.Now.ToShortTimeString();
            string errorMessage = "Exception generate on " + dataTime;
            System.Web.HttpContext context = System.Web.HttpContext.Current;

            errorMessage += "\n\n Page Location: " + context.Request.Url;

            errorMessage += "\n\n Message: " + ex.Message;

            errorMessage += "\n\n Source: " + ex.Source;

            errorMessage += "\n\n Method: " + ex.TargetSite;
            errorMessage += "\n\n Stack Trace: \n\n" + ex.StackTrace;

            if (BallonShopConfiguration.EnableErrorLogEmail)
            {
                string from = BallonShopConfiguration.MailFrom;

                string to = BallonShopConfiguration.ErrorLogEmail;

                string subject = "Ballon Shop Report";
                
                string body = errorMessage;
             
                SendMail(from, to, subject, body);

            }
    Thursday, October 26, 2017 1:02 AM

Answers

  • Hello HardenWang,

    What type of mail are you using , it have plenty of domain server under Microsoft . If you use "hotmail.com", your smtp server host should be "smtp-mail.outlook.com". The following is my testing code  and it works well.

                SmtpClient mailClient = new SmtpClient("smtp-mail.outlook.com");   
                mailClient.Credentials = new NetworkCredential("YourEmailAddress", "YourEmailPassword");
                MailMessage mailMessage = new MailMessage("xxxx@hotmail.com", "xxxx@hotmail.com", "Test", "Test");
                mailClient.EnableSsl = true;
                mailClient.Send(mailMessage);

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Fei HuModerator Thursday, October 26, 2017 9:55 AM
    • Marked as answer by HardenWang Thursday, October 26, 2017 11:46 AM
    • Unmarked as answer by HardenWang Thursday, October 26, 2017 11:46 AM
    • Marked as answer by HardenWang Thursday, October 26, 2017 11:59 AM
    • Unmarked as answer by HardenWang Thursday, October 26, 2017 11:59 AM
    • Marked as answer by HardenWang Thursday, October 26, 2017 12:01 PM
    Thursday, October 26, 2017 8:15 AM
    Moderator

All replies

  • I WONDER IF THERE WAS SOME PROBLEM WITH MICROSOFT'S SMTP SERVER?
    Thursday, October 26, 2017 1:03 AM
  • Hello HardenWang,

    What type of mail are you using , it have plenty of domain server under Microsoft . If you use "hotmail.com", your smtp server host should be "smtp-mail.outlook.com". The following is my testing code  and it works well.

                SmtpClient mailClient = new SmtpClient("smtp-mail.outlook.com");   
                mailClient.Credentials = new NetworkCredential("YourEmailAddress", "YourEmailPassword");
                MailMessage mailMessage = new MailMessage("xxxx@hotmail.com", "xxxx@hotmail.com", "Test", "Test");
                mailClient.EnableSsl = true;
                mailClient.Send(mailMessage);

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Fei HuModerator Thursday, October 26, 2017 9:55 AM
    • Marked as answer by HardenWang Thursday, October 26, 2017 11:46 AM
    • Unmarked as answer by HardenWang Thursday, October 26, 2017 11:46 AM
    • Marked as answer by HardenWang Thursday, October 26, 2017 11:59 AM
    • Unmarked as answer by HardenWang Thursday, October 26, 2017 11:59 AM
    • Marked as answer by HardenWang Thursday, October 26, 2017 12:01 PM
    Thursday, October 26, 2017 8:15 AM
    Moderator
  • HI,I REGISTER A HOTMAIL ACCOUNT EXCLUSIVELY,BUT THE PROBLEM STILL EXISTS WITH IT,HERE IS MY ERROR MESSAGE:

    Client was not authenticated to send anonymous mail during MAIL FROM [HK2PR0401CA0008.apcprd04.prod.outlook.com]”

    CAN YOU HELP ME SOLVE IT? THANK YOU.

    Tuesday, October 31, 2017 12:09 PM
  • Hello HardenWang,

    Try to use the below code.

    SmtpServer oServer = new SmtpServer("smtp.live.com");

    "smtp.live.com" is suitable for all otmail/Live/Outlook.com SMTP server and it requires explicit SSL (TLS) connection to do user authentication.

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 1, 2017 8:11 AM
    Moderator