I want to send mail through outlook. i want to send my outlook mail id to another mail id. I had tried two methods but unable to find the solution. Can you suggest me a possible methods to recover my probs. for your reference i am send my code to you.
In 1st method, I am getting this Error
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [SG2PR06CA0239.apcprd06.prod.outlook.com]".
In 2nd method, I am getting this Error
"Failure sending mail."
protected void btnmail_Click(object sender, EventArgs e)
{
//Outlook access 1st method
SmtpClient smtpClient = new SmtpClient("smtp.office365.com", 587); //587
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential("outlook mail addr", "Password");
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("From outlook mail addr", "CTMIS-no-reply");
mail.To.Add(new MailAddress("To outlook mail addr"));
//mail.CC.Add(new MailAddress("jcborlagdan@ymail.com"));
smtpClient.Send(mail);
//2nd MEthod
SmtpClient sClient = new SmtpClient("domain-com.mail.protection.outlook.com");
MailMessage message = new MailMessage();
try
{
sClient.Port = 25;
sClient.EnableSsl = true;
sClient.Credentials = new NetworkCredential("outlook mail addr", "Password");
message.Body = "Test";
message.From = new MailAddress("From outlook mail addr");
//message.To = new MailAddress("To outlook mail addr");
message.Subject = "Test";
//message.To = new MailAddress("software-trainee@blissgroup.com");
message.CC.Add(new MailAddress("CC outlook mail addr"));
sClient.UseDefaultCredentials = false;
sClient.Send(message);
}
catch (Exception ex)
{
lblconfrim.Text = ex.Message;
}
}