【问题标题】:Tracking email with SendGrid alike MailGun使用类似 MailGun 的 SendGrid 跟踪电子邮件
【发布时间】:2017-04-07 06:25:15
【问题描述】:

我正在研究一些电子邮件服务,例如 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 请求查看电子邮件状态。

你能帮帮我吗?

【问题讨论】:

    标签: api events sendgrid webhooks mailgun


    【解决方案1】:

    希望你现在明白了,

    但这里是为了未来: 您应该使用 webhook,如下所示:

    1 配置应用程序:clicktrack、opentrack& .what_you_want_to_tarck.. & eventnotify 为 true,使用 Get & activate

    2 使用 RequestPin 创建一个 POSTURL,

    3 从仪表板中的邮件设置中激活事件通知并检查您想要的事件,当您按下 testYourIntegration 按钮时,您应该将示例发布请求发送到创建的 url。

    1. 按照官方文档中的说明使用此代码:

      字符串 apikey = "......." sg = sendgrid.SendGridAPIClient(apikey=os.environ.get(apikey)) to_email = 电子邮件(“....@gmail.com”)
      from_email =电子邮件(“....”) 主题='...' content = Content("text/plain","尝试 SendGrid") 邮件 = 邮件(发件人电子邮件、主题、收件人电子邮件、内容) response = sg.client.mail.send.post(request_body=mail.get())

      现在,去打开或点击代码发送的电子邮件,解除事件..,然后返回

      https://requestb.in/Your_bin_id?inspect

    &您应该会在一段时间后看到通知

    更多,你可以去:

    https://requestb.in/api/v1/bins/bin_id/requests
    

    使用代码执行 Get 请求并仅解析 JSON

    【讨论】:

      猜你喜欢
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-30
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多