I am trying to use MailKit for sending email via office 365 for a web app that I am currently developing.
I have had various issues in the past with office 365 and sending emails and this evening I have stumbled across multiple articles and stack questions addressing office 365 and sending via smtp and MailKit being the preferred option.
I am using this code
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Simon Price", "simon.price@xxxx.co.uk"));
message.To.Add(new MailboxAddress("Recipient Nasme", "emailAddress"));
message.Subject = "Still hitting spam";
message.Body = new TextPart("html")
{
Text = @"sample test"
};
using (var client = new SmtpClient())
{
client.Connect("smtp.office365.com", 587, SecureSocketOptions.Auto);
// Note: only needed if the SMTP server requires authentication
client.Authenticate("simon.price@sxxx.co.uk", "xxxx");
client.Send(message);
client.Disconnect(true);
}
Which does send the email, however, it continually hits the spam folders of each recipient. I very much suspect this is me missing a configuration, however I cannot see where I am going wrong in this and would appreciate some help.
Resources I have looked at include but not exhausted (i may have missed some)
https://github.com/jstedfast/MailKit
https://dotnetcoretutorials.com/2017/11/02/using-mailkit-send-receive-email-asp-net-core/
Does Office 365 have a preferred way of sending attachments when using MailKit?
Authenticating to Office 365 Outlook IMAP using MailKit fails for a specific user
https://unop.uk/sending-email-in-.net-core-with-office-365-and-mailkit/