Search code examples
outlookvstooutlook-addinoffice-addinssystem.net.mail

Cannot send SMTP Email from Outlook VSTO Addin


I have a SendEmail method developed with System.Net.Mail that works fine. Calling it from my VSTO Outlook Addin, I get an error: A call to SSPI failed. The inner error contains "Function not supported".

I tried to send the same email from a regular c# environment (that worked), and from my Outlook VSTO add-in that did not.

Is there a reason why the smtp email cannot be sent from the Addin?

Solution (thanks to Eugene), I added

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

to the SendEmail method and now the Emails are sent.


Solution

  • Given the nature of the exception, it seems like you're more likely to have an email server problem than anything else.

    Also it makes sense to check what TLS version is used in the code. SSPI stands for Security Support Provider Interface, so it makes sense try to find the difference between two .net applications. TLS is a starting point, see How to enable TLS 1.2 for more information.

    You may consider your Outlook VSTO add-in as a regular .net application. There are minor differences like availability of configurations files and etc. If you need to put something into a config file you need to create a config for the host application which is Outlook in your case. Keep that in mind when developing VSTO add-ins.