2

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/

Simon Price
  • 3,011
  • 3
  • 34
  • 98
  • The choice of a mailer (MailKit) makes no difference regarding your email being flagged as Junk. Provided that you are using an email service such as Office 365 to send your emails, the primary indicator of Junk is the content of your emails. Use a service that analyzes your email for a SPAM rating. Check that your domain is not listed on one of the blacklists for SPAM. – John Hanley Sep 13 '21 at 03:05
  • @JohnHanley, Its a brand new domain that I set up that I am trying to send from so shouldnt be blacklisted, but I suspect I need to get this into a whitelist in O365 Admin Centre then? – Simon Price Sep 13 '21 at 06:58
  • Most likely your email content is detected as SPAM. Use a service to rate one of your emails. Office 365 does not whitelist email. The recipient would need to whitelist your email address in their email client. – John Hanley Sep 13 '21 at 07:00

0 Answers0