Reputation: 233
I am trying to send emails through Outlook 365. I get the following error. SMTP Error: [MustIssueStartTlsFirst] Message: The SMTP server requires a secure connection or the client was not authenticated.
My code:
System.Net.NetworkCredential cred = new System.Net.NetworkCredential(mailInfo.FromAddr, mailInfo.Password);
SmtpClient mailClient = new SmtpClient(mailInfo.Server) {
Port = mailInfo.Port,
EnableSsl = true, //mailInfo.SSL,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = cred,
TargetName = "STARTTLS/smtp.office365.com"
};
MailMessage message = new MailMessage {
From = new MailAddress(mailInfo.FromAddr, mailInfo.FromName),
Subject = "Manifest Processor Shipment Report - Manifest: " + shipment.ManifestNumber,
Body = BuildManifestEmailBody(shipment),
Priority = MailPriority.High,
IsBodyHtml = true
};
What is strange, is I have a small test program that runs, using the same code.
Upvotes: 1
Views: 1684
Reputation: 49395
See Outlook Mail REST API reference in MSDN. The Outlook Mail API lets you read, create, and send messages and attachments, view and respond to event messages, and manage folders in a user's mailbox in Office 365 or Exchange Online.
Also you may find EWS helpful. See EWS Managed API, EWS, and web services in Exchange for more information.
Upvotes: 2