In the C# tab of the getting started of maingun API, I find the following code.

public static RestResponse SendSimpleMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <me@samples.mailgun.org>");
       request.AddParameter("to", "sergeyo@profista.com");
       request.AddParameter("to", "serobnic@mail.ru");
       request.AddParameter("subject", "Hello");
       request.AddParameter("text", "Testing some Mailgun awesomness!");
       request.Method = Method.POST;
       return client.Execute(request);
}

When I google the name of the class, I find several reference to this class in different contexts. However, I can't seem to find the fully qualified name of the RestRequest class anywhere on the mailgun website, google or MSDN to find it's documentation.

Anybody can point out where is this class defined ?

有帮助吗?

解决方案

The code looks like it uses RestSharp.

其他提示

RestSharp is available from NuGet. Install it from there.

I run in the same issue. But I found out that if you are using JAVA 8 you don't needs any external librairy but just what java provide already here is my code example.

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

public class EmailDAO {

public static Response sendNewPasswordMessage() {
Client client = ClientBuilder.newClient();
client.register(new BasicAuthenticator("api","yourkey"));

WebTarget target = client.target("https://api.mailgun.net/v2/your-domain/messages");

MultivaluedMap formData = new MultivaluedHashMap();
formData.add("from", "Test <postmaster@test.net>");
formData.add("to", "anyone@test.net");
formData.add("subject", "Hello world");
formData.add("html", "Hello world <br /> <br /> ");

Invocation invocation = target.request().buildPost(Entity.form(formData));
return invocation.invoke();
}

}

Hopes it helps.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top