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("[email protected]", "Auto Generated Email"); mailMessage.To.Add(new MailAddress("[email protected]")); mailMessage.CC.Add(new MailAddress("[email protected]")); 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("[email protected]", "*******"); smtpClient.Credentials = basicAuthenticationInfo; smtpClient.Timeout = 20000; smtpClient.Send(mailMessage); smtpClient.Dispose(); MessageBox.Show("E-mail Sent Successfully.....!!");