Exception using default SMTP credentials on Office365 - Client was not authenticated to send anonymous mail during MAIL FROM

Thanks to this post, I was able to resolve our issues. We migrated mailboxes to O365 from a hybrid setup at Rackspace. The mailbox being used to send was not previously an Exchange account but became one after the migration.

mySmtpClient = New SmtpClient("smtp.office365.com")
mySmtpClient.Port = 587
mySmtpClient.EnableSsl = True
mySmtpClient.Credentials = New System.Net.NetworkCredential("[email protected]", "password", "domain.com")
mySmtpClient.Send(Msg)

Previous setup did not require us to provide port or enable ssl or even put the domain in the credential parameters. Hope this helps with folks who have to work with VB scripts automating emails via SMTP with Office 365.


Although the workaround I mentioned in the answer update did work, I was not happy about manually fetching those values. The solution for me was to remove the line

smtpClient.UseDefaultCredentials = true;

from the original code I posted. It turns out that smtpClient is initialized with the default credentials I set up in the web.config, and the above removed line was overwriting them with empty strings from CredentialCache.DefaultCredentials. I still don't know why CredentialCache.DefaultCredentials is empty or when this is supposed to be populated from the web.config, but this was the source of my problem.

If anyone has any further insight into this please post a better answer!