目录

c-mailgun-发送邮件测试

目录

c# mailgun 发送邮件测试

1、 登录

官网注册账号,并激活账号。

2、登录账号后进入查看 domain

https://i-blog.csdnimg.cn/blog_migrate/10fc560ac198213edde280cb9713cbec.png

上面的即是 mailgun默认给予免费测试的domain。

3、点击 domain name 查看域名信息,注意发邮件要用到

https://i-blog.csdnimg.cn/blog_migrate/319b0686f9ea8c846404f72ca812b8ae.png

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 中

https://i-blog.csdnimg.cn/blog_migrate/f8f22cfb88e8472051008d8c21eff5a9.png

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);
        }