0

I am trying to use my outlook SMTP settings in our web application to send mail to users. The mail is not reaching any of the recipients, but I also don't receive any application errors. I am configuring the mail settings in web.config as below:

<smtp deliveryMethod="Network" from="[email protected]">
        <network defaultCredentials="false" host="smtp.office365.com" port="587" userName="[email protected]" password="SuperSecret123(not real)" enableSsl="true"/>
      </smtp>

The code that sends the mail message is like this:

var C = new SmtpClient();
            var M = new MailMessage(ConfigurationManager.AppSettings["fromemail"],to,subject,message);
            M.IsBodyHtml = true;
            C.Send(M);

ConfigurationManager.AppSettings["fromemail"] is the same as my from mail address. All passed variables are what they should be. If I swap out my mail settings for a test gmail account, it works. This leads me to assume that I am being spammed, but I can't confirm this because none of my test mail accounts have the messages in the spam folder, so I assume they're getting nuked on the outlook server BEFORE they're sent.

In addition, I am using a GMail account to test, so I can't really go ahead and use an Office 365 specific solution.

3 Answers 3

1

Juann,

Consider using the EWS (Exchange Web Services) for sending emails. See EWS Managed API, EWS, and web services in Exchange for more information.

3
  • How would I use EWS to send mail via GMail, or any other non-exchange provider? Mar 11, 2015 at 10:22
  • There is no way. It is for Exchange only. I see Office365 tag, so it is expected that you use the hosted exchange server. Consider using BCL classes or any other third-party components instead. Mar 11, 2015 at 10:38
  • I asked because when testing the application, we use a gmail account. Mar 11, 2015 at 11:01
1

In addition, for Office 365, you could consider using Mail REST APIs also.

https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#MessageoperationsSendmessages

1
  • I didn't mention in the question, but I use my GMail account for testing, so I can't really use anything that's not vanilla SMTP. Mar 12, 2015 at 7:15
0

The FROM mail address must be an existing address in Office 365. I often set up a SMTP server relaying to Office 365, and I can then view the errors in the logs of my local SMTP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.