繁体   English   中英

C#Appharbor和Mailgun不发送电子邮件

[英]C# Appharbor and Mailgun Not Sending Email

我正在使用Mailgun nuget包在我的应用程序中发送电子邮件。 我关注了这篇文章

http://support.appharbor.com/discussions/problems/906-mailgun-error-smtp-client

作为我的起点。 这是我使用客户端对API的调用

string domain = ConfigurationManager.AppSettings["MAILGUN_SMTP_SERVER"];
string api_key = ConfigurationManager.AppSettings["MAILGUN_API_KEY"];
MailgunClient client = new MailgunClient(domain, api_key);
                    client.SendMail(new System.Net.Mail.MailMessage("admin@" + domain, "xxxx@example.com")
                    {
                        Subject = "Hello from mailgun",
                        Body = "this is a test message from mailgun."
                    });

这是我的web.config设置

<add key="MAILGUN_API_KEY" value="key-*********************" />
<add key="MAILGUN_SMTP_SERVER" value="xmailgunapp.mailgun.org" />

这在我的本地应用程序中有效,但是,当我将其推送到Appharbor时,出现错误

System.Exception:找不到域:smtp.mailgun.org

似乎还有更多的应用程序设置

http://support.appharbor.com/kb/add-ons/using-mailgun

但是我找不到任何有关如何将它们集成到软件包客户端的文档。 谁能告诉我我可能做错了什么?

domain属性不是SMTP服务器,而是您自己的域,MailGun会在注册时为您提供该域:

string domain = "staafl.mailgun.org";

请注意,在这种情况下,您不是使用SMTP,而是使用HTTP服务接口-请参阅http://documentation.mailgun.com/user_manual.html#sending-messages

如果要使用SMTP,则可以使用.NET的SmtpClient类和MAILGIN_SMTP_LOGIN / MAILGIN_SMTP_SERVER等配置设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM