c-mailgun-发送邮件测试
目录
c# mailgun 发送邮件测试
1、 登录
官网注册账号,并激活账号。
2、登录账号后进入查看 domain
上面的即是 mailgun默认给予免费测试的domain。
3、点击 domain name 查看域名信息,注意发邮件要用到
4、测试要发送的邮箱,必须要把 邮箱地址添加上mailgun中的
Authorized Recipients 中否则会提示:" Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings. "
具体设置方法 点击 mailgun的 Account Settings 把要测试的邮件添加到 Recipients 中
5、实现代码 mailgun 中有(示例)
public static IRestResponse SendSimpleMessage()
{
RestClient client = new RestClient();
client.BaseUrl = new Uri("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator("api",
"key-f6dd9wewe32d2223345026e3d0423968a18ecb37ad1");
RestRequest request = new RestRequest();
request.AddParameter("domain", "sandbox757cf4babd96473098b300705a243434.mailgun.org", ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter("from", "postmaster@sandbox757cf4babd96473098b300705a243434.mailgun.org");
request.AddParameter("to", "1787940846@qq.com");
request.AddParameter("subject", "Hello");
request.AddParameter("text", "Testing some Mailgun awesomness!");
request.Method = Method.POST;
return client.Execute(request);
}