Guttorm
Guttorm

Reputation: 21

Sending Sparkpost smtp Email using c#

I have looked at numerous answers in stack overflow and other places and I still cannot find a good example on how to:

in C#, Successfully send email via sparkpost smtp after STARTTLS was introduced. Documentation in Sparkpost (https://www.sparkpost.com/docs/getting-started/getting-started-sparkpost/, search for starttls) refers to the following settings:

SMTP host: smtp.sparkpostmail.com Port: 587 or 2525 Encryption: STARTTLS Username: SMTP_Injection Password:

In my current applications, in web.config, I configure sparkpost smtp like so:

        <network host="smtp.sparkpostmail.com" port="587" userName="SMTP_Injection" password="..." enableSsl="true" />

This worked fine until the start of july. And then TLS 1.0 was no longer supported. So I would like to get our email working again

But how does STARTTLS come into play ?

Upvotes: 2

Views: 1075

Answers (1)

APOUGHER
APOUGHER

Reputation: 49

I added the ServicePointManager.SecurityProtocol line to my smtp C# code and it all started working again. Hope this helps.

SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.sparkpostmail.com";
smtp.Port =  587; // 2525
smtp.EnableSsl = true;
//NOTE THE LINE BELOW
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
smtp.Credentials = new NetworkCredential("SMTP_Injection", "YOURKEY");

Upvotes: 1

Related Questions