wahab ahmed

wahab ahmed

  • 2k
  • 81
  • 230

Email Not Send on office365

Jan 19 2022 7:20 AM

I have write below code behind button when press button it show error like "Email Sending Failed!" kindly help me to sortout this problem.

 

 

string pathexp =  "test.pdf";
            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("xyz@xyz.ae", "Auto Generated Email");
            mailMessage.To.Add(new MailAddress("xyz@xyz.ae"));
            mailMessage.CC.Add(new MailAddress("abc@xyz.ae"));
            mailMessage.Subject = " Approval Required ";
            mailMessage.Body += "Dear";
            
            mailMessage.Attachments.Add(new Attachment(pathexp));

            mailMessage.IsBodyHtml = true;
            SmtpClient smtpClient = new SmtpClient("smtp.office365.com");

            smtpClient.UseDefaultCredentials = false;
            smtpClient.EnableSsl = false;
            smtpClient.Port = 25;
            System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("xyz@xyz.ae", "*******");
            smtpClient.Credentials = basicAuthenticationInfo;
            smtpClient.Timeout = 20000;
            smtpClient.Send(mailMessage);
            smtpClient.Dispose();
            MessageBox.Show("E-mail Sent Successfully.....!!");


Answers (1)