使用C#发送Sparkpost smtp电子邮件

时间:2018-08-01 15:37:35

标签: email smtp starttls sparkpost

我已经在堆栈溢出和其他地方查看了许多答案,但仍然找不到如何做到这一点的好例子:

在C#中,在引入STARTTLS后成功通过sparkpost smtp发送电子邮件。 Sparkpost中的文档(https://www.sparkpost.com/docs/getting-started/getting-started-sparkpost/,搜索starttls)涉及以下设置:

SMTP主机:smtp.sparkpostmail.com 端口:587或2525 加密:STARTTLS 用户名:SMTP_Injection 密码:

在当前应用程序的web.config中,我像这样配置sparkpost smtp:

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

...

在7月初之前,它一直运行良好。然后,不再支持TLS 1.0。所以我想让我们的电子邮件重新工作

但是STARTTLS如何发挥作用?

1 个答案:

答案 0 :(得分:0)

我在我的smtp C#代码中添加了ServicePointManager.SecurityProtocol行,并且所有这些再次开始工作。希望这会有所帮助。

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");