使用类似 MailGun 的 SendGrid 跟踪电子邮件
Tracking email with SendGrid alike MailGun
我正在研究一些电子邮件服务,如 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 中找不到相同的功能?我正在疯狂地搜索他们的文档。我找到了 webhook,但这不是我需要的。我只想像 MailGun 那样通过 http 请求查看电子邮件状态。
你能帮帮我吗?
希望你现在已经明白了,
但这是为了未来:
您应该使用 webhook,如下所示:
1 配置应用程序:clicktrack、opentrack& .what_you_want_to_tarck.. & eventnotify 为真,使用 Get & activate
2 使用 RequestPin 创建一个 POSTURL,
3 从仪表板中的邮件设置激活事件通知并检查您想要的事件,当您按下 testYourIntegration 按钮时,您应该将示例 post 请求发送到创建的 url。
按照官方文档中的说明使用此代码:
string apikey = "......"
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get( apikey ))
to_email = 电子邮件("...@gmail.com")
from_email =电子邮件 ("...")
主题='...'
内容 = 内容("text/plain","Trying SendGrid")
mail = 邮件(from_email, 主题, to_email, 内容)
响应 = sg.client.mail.send.post(request_body=mail.get())
现在,打开或点击代码发送的电子邮件,取消活动..,然后返回
& 稍后您应该会看到通知
如需更多信息,您可以前往:
https://requestb.in/api/v1/bins/bin_id/requests
使用代码执行 Get 请求并解析 JSON
我正在研究一些电子邮件服务,如 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 中找不到相同的功能?我正在疯狂地搜索他们的文档。我找到了 webhook,但这不是我需要的。我只想像 MailGun 那样通过 http 请求查看电子邮件状态。
你能帮帮我吗?
希望你现在已经明白了,
但这是为了未来: 您应该使用 webhook,如下所示:
1 配置应用程序:clicktrack、opentrack& .what_you_want_to_tarck.. & eventnotify 为真,使用 Get & activate
2 使用 RequestPin 创建一个 POSTURL,
3 从仪表板中的邮件设置激活事件通知并检查您想要的事件,当您按下 testYourIntegration 按钮时,您应该将示例 post 请求发送到创建的 url。
按照官方文档中的说明使用此代码:
string apikey = "......" sg = sendgrid.SendGridAPIClient(apikey=os.environ.get( apikey )) to_email = 电子邮件("...@gmail.com")
from_email =电子邮件 ("...") 主题='...' 内容 = 内容("text/plain","Trying SendGrid") mail = 邮件(from_email, 主题, to_email, 内容) 响应 = sg.client.mail.send.post(request_body=mail.get())现在,打开或点击代码发送的电子邮件,取消活动..,然后返回
& 稍后您应该会看到通知
如需更多信息,您可以前往:
https://requestb.in/api/v1/bins/bin_id/requests
使用代码执行 Get 请求并解析 JSON