简体   繁体   中英

C# Appharbor and Mailgun Not Sending Email

I am sending an email in my app using the Mailgun nuget package. I followed this post

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

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

<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

System.Exception: Domain not found: smtp.mailgun.org

It appears that there are more app settings

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:

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 .

If you want to use SMTP, you can use .NET's SmtpClient class and the MAILGIN_SMTP_LOGIN/MAILGIN_SMTP_SERVER etc configuration settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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