Search code examples
outlooksmtpclient

Unable to send to Outlook using SMTP from 3rd party server


I am sending email through a web program using smtp on my hosting server (IONOS). When I send a message using SmtpClient the send seems to work (no exception), but the message is never delivered to my Office 365 email address. I am sending the email to 3 targets ([email protected], [email protected], and [email protected]). The gmail and IONOS targets receive the message fine. The outlook target does not. Here is a code snippet of how I am sending...

        string Server = "smtp.ionos.com";
        string User="[email protected]";
        string Password="MyPassword";
        int Port = 587;
        MailMessage mm = new MailMessage();
        mm.Subject = "Test Message";
        mm.Body = "Test Message";
        mm.To.Add(new MailAddress("[email protected]"));
        mm.To.Add(new MailAddress("[email protected]"));
        mm.To.Add(new MailAddress("[email protected]"));
        var client = new SmtpClient(Server, Port);
        client.EnableSsl = true;
        System.Net.NetworkCredential cs = new System.Net.NetworkCredential(User, Password);
        client.Credentials = cs;
        try {
            client.Send(mm);
            ViewBag.Message = "It worked";
        }
        catch (Exception ex)
        {
            ViewBag.Message = $"Message: {ex.Message}\n\r{ex.InnerException.Message}";
        }

If I change the outgoing server to "smtp.gmail.com" (and corresponding credentials) it sends fine and the message is delivered to all three recipients. I am not getting any BounceBack message so I don't know how to troubleshoot.

Are there required CName records in the DNS that are needed to make this work? Does Outlook (or Exchange server) require anything special in the DNS to work?

I have tried sending to port 465, and also 25, neiher of which work.


Solution

  • Looks like the message is sent out successfully if it was delivered to other recipients. Try to check the Junk E-mails folder or spam filters on the O365 side.