我在 Exchange Online 服务上有一个邮件帐户。现在我正在尝试测试我是否能够通过 c# 应用程序向客户(在各种域和 Microsoft Office 365 上)发送邮件
我尝试实现以下代码,但出现错误
“根据验证程序,远程证书无效。”
MailMessage mail = null;
mail = new MailMessage();
string[] strToList = "abc@gmail.com"
foreach (string strID in strToList)
{
if (strID != null)
{
mail.To.Add(new MailAddress(strID));
}
}
mail.From = "demo@onmicrosoft.com";
mail.Subject = "testing"
mail.IsBodyHtml = true;
mail.Body = "mail body";
SmtpClient client = new SmtpClient("smtp.outlook.office365.com");
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
NetworkCredential cred = new System.Net.NetworkCredential("demo@onmicrosoft.com", "mypassword");
client.Credentials = cred;
client.Send(mail);
如果我做错了什么,请指教。提前非常感谢。