我正在研究一些电子邮件服务,如SensdGrid和MailGun。
在MailGun文档中,我发现了一个非常有用的功能:https://documentation.mailgun.com/user_manual.html#events
您可以简单地向MailGun API询问触发的事件,并发送一些过滤器。它非常简单而且功能强大。这是一个例子:
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class EventsDateTimeRecipientChunk
{
public static void Main (string[] args)
{
Console.WriteLine (EventsDateTimeRecipient ().Content.ToString ());
}
public static IRestResponse EventsDateTimeRecipient ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
request.Resource = "{domain}/events";
request.AddParameter ("begin", "Fri, 3 May 2013 09:00:00 -0000");
request.AddParameter ("ascending", "yes");
request.AddParameter ("limit", 25);
request.AddParameter ("pretty", "yes");
request.AddParameter ("recipient", "joe@example.com");
return client.Execute (request);
}
}
和输出样本:
{
"items": [
{
"tags": [],
"timestamp": 1376325780.160809,
"envelope": {
"sender": "me@samples.mailgun.org",
"transport": ""
},
"event": "accepted",
"campaigns": [],
"user-variables": {},
"flags": {
"is-authenticated": true,
"is-test-mode": false
},
"message": {
"headers": {
"to": "user@example.com",
"message-id": "20130812164300.28108.52546@samples.mailgun.org",
"from": "Excited User <me@samples.mailgun.org>",
"subject": "Hello"
},
"attachments": [],
"recipients": [
"user@example.com"
],
"size": 69
},
"recipient": "user@example.com",
"method": "http"
}
],
"paging": {
"next":
"https://api.mailgun.net/v3/samples.mailgun.org/events/W3siY...",
"previous":
"https://api.mailgun.net/v3/samples.mailgun.org/events/Lkawm..."
}
}
我是否有可能在SendGrid中找不到相同的功能?我在他们的文件中疯狂搜索..我找到了webhooks,但这不是我需要的。我只想看看像MailGun这样的http请求的电子邮件状态。
你能帮助我吗?
答案 0 :(得分:0)
希望你现在明白了,
然而,未来的未来: 您应该使用webhooks,如下所示:
1配置应用程序:clicktrack,opentrack&amp; .what_you_want_to_tarck ..&amp;使用Get&amp; amp;事件通知为真激活
2使用RequestPin创建一个POSTURL,
3从仪表板中的邮件设置激活事件通知。检查所需的事件,当您按下testYourIntegration按钮时,您应该获得创建的URL的示例发布请求。
使用官方文档中描述的代码:
string apikey =&#34; .......&#34;
sg = sendgrid.SendGridAPIClient(apikey = os.environ.get(apikey))
to_email =电子邮件(&#34; .... @ gmail.com&#34;)
from_email =电子邮件(&#34; ....&#34;)
subject =&#39; ...&#39;
content = Content(&#34; text / plain&#34;,&#34; Trying SendGrid&#34;)
mail = Mail(from_email,subject,to_email,content)
response = sg.client.mail.send.post(request_body = mail.get())
现在,去&amp;打开或点击代码发送的电子邮件,以解除事件..,然后返回
&安培;你应该在一段时间后看到通知
更多信息,您可以访问:
https://requestb.in/api/v1/bins/bin_id/requests
使用代码&amp;做一个Get请求只需解析JSON