简体   繁体   English

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

[英]C# Appharbor and Mailgun Not Sending Email

I am sending an email in my app using the Mailgun nuget package. 我正在使用Mailgun nuget包在我的应用程序中发送电子邮件。 I followed this post 我关注了这篇文章

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

as my starting point. 作为我的起点。 This is my call to the API using the 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."
                    });

Here are my web.config settings 这是我的web.config设置

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

This works in my local application, however, when I push this to Appharbor I get the error 这在我的本地应用程序中有效,但是,当我将其推送到Appharbor时,出现错误

System.Exception: Domain not found: smtp.mailgun.org System.Exception:找不到域:smtp.mailgun.org

It appears that there are more app settings 似乎还有更多的应用程序设置

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

but I am cannot find any documentation on how to integrate them into the package client. 但是我找不到任何有关如何将它们集成到软件包客户端的文档。 Can anyone tell me what I might be doing incorrectly? 谁能告诉我我可能做错了什么?

The domain property is not the SMTP server, but your own domain, which MailGun gives you upon registering: domain属性不是SMTP服务器,而是您自己的域,MailGun会在注册时为您提供该域:

string domain = "staafl.mailgun.org";

Note that in this case you are not using SMTP, but the HTTP service interface - see http://documentation.mailgun.com/user_manual.html#sending-messages . 请注意,在这种情况下,您不是使用SMTP,而是使用HTTP服务接口-请参阅http://documentation.mailgun.com/user_manual.html#sending-messages

If you want to use SMTP, you can use .NET's SmtpClient class and the MAILGIN_SMTP_LOGIN/MAILGIN_SMTP_SERVER etc configuration settings. 如果要使用SMTP,则可以使用.NET的SmtpClient类和MAILGIN_SMTP_LOGIN / MAILGIN_SMTP_SERVER等配置设置。

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

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