【发布时间】:2018-01-11 04:59:57
【问题描述】:
我可以使用 Mailkit 通过组织 smtp 服务器从 azure webjob 发送电子邮件吗?还是我需要使用 Sendgrid?
Mine 是一个 .net core 1.1 控制台应用程序,然后我将其托管为 azure webjob。
由于某种原因,我无法使用组织 Smtp 服务器让我的网络作业与 Mailkit 一起工作。作业成功运行,不记录任何错误。但无法发送邮件..
这是我使用 mailkit 的代码
using (var client = new SmtpClient())
{
try {
// For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
Logger.LogInformation("Ready to connect to smtp server");
client.Connect(Constants.SMTP_HOST, 25, false);
Logger.LogInformation("connected to smtp server");
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
Logger.LogInformation("Ready to send email");
client.Send(message);
}
catch (Exception ex) {
Logger.LogError("An error occurred");
Logger.LogError(ex.StackTrace);
}
finally {
client.Disconnect(true);
}
}
【问题讨论】:
-
@TomSun 我已经迷失了方向。我会尽快发布更新。谢谢。
标签: console-application .net-core sendgrid azure-webjobs mailkit