FluentEmail icon indicating copy to clipboard operation
FluentEmail copied to clipboard

Use build in mailgun template ?

Open JK-404 opened this issue 3 years ago • 0 comments

With mailgun is possible to use templates which are defined in your mailgun account and access them via code. An example for that would be:

public static RestResponse SendSimpleMessage() {
	RestClient client = new RestClient();
	client.BaseUrl = "https://api.mailgun.net/v3";
	client.Authenticator =
	new HttpBasicAuthenticator("api",
							   "ENTER_API_KEY_HERE");
	RestRequest request = new RestRequest();
	request.AddParameter("domain", "xn--xx-x-0wc.de", ParameterType.UrlSegment);
	request.Resource = "{domain}/messages";
	request.AddParameter("from", "Mailgun Sandbox <[email protected]>");
	request.AddParameter("to", "Hans Wurst <[email protected]>");
	request.AddParameter("subject", "Hello xx xx");
	request.AddParameter("template", "password_forgotten");
	request.AddParameter("h:X-Mailgun-Variables", "{"test": "test"}");
	request.Method = Method.POST;
	return client.Execute(request);
}
// Send an email using your active template with the above snippet
// You can see a record of this email in your logs: https://app.mailgun.com/app/logs.

Especially this lines

	request.AddParameter("template", "password_forgotten");
	request.AddParameter("h:X-Mailgun-Variables", "{"test": "test"}");

One to access the template and the other one to fill the template. Is this possible with mailgun ?

JK-404 avatar Jan 06 '22 08:01 JK-404