由Gmail自动解析并添加日历事件的电子邮件

时间:2019-05-07 13:29:45

标签: c# email gmail google-calendar-api google-schemas

我希望这个问题可以在这里提出,因为它可以代替我对Google Calendar API的使用,我认为应该可以。

https://stackoverflow.com/help/on-topic

当您收到有关航班,音乐会或餐厅预订等活动的电子邮件时,该电子邮件会自动添加到您的日历中。

https://support.google.com/calendar/answer/6084018?co=GENIE.Platform%3DDesktop&hl=en

我认为这是一个非常简洁的功能,但我想知道是否可以创建自动显示在我的日历中的电子邮件。我目前正在使用Calendar API,Google.Apis.Calendar.v3,但是如果我可以使用它,我的应用程序就不再需要处理凭据了。

根据支持页面无法显示电子邮件的情况:

如果电子邮件为:

,则不会显示活动
  • 已发送到邮件列表
  • 由抄送给您
  • 从另一个电子邮件帐户重定向

仅当事件来自企业的确认电子邮件中时,才会添加事件:

  • 航班
  • 酒店
  • 餐馆
  • 票务活动,例如电影和音乐会

我一直在阅读Events from Gmail,并在下面创建了示例。

https://developers.google.com/gmail/markup/google-calendar

https://developers.google.com/gmail/markup/getting-started

https://developers.google.com/gmail/markup/reference/event-reservation

<html>
<body>
    <script type="application/ld+json">
        {
        "@context": "http://schema.org",
        "@type": "EventReservation",
        "reservationNumber": "E123456789",
        "reservationStatus": "http://schema.org/Confirmed",
        "underName": {
        "@type": "Person",
        "name": "Oscar Andersson"
        },
        "reservationFor": {
        "@type": "Event",
        "name": "Foo Fighters Concert",
        "performer": {
        "@type": "Organization",
        "name": "The Foo Fighters",
        "image": "http://www.amprocktv.com/wp-content/uploads/2027/01/foo-fighters-1-680x383.jpg"
        },
        "startDate": "2019-05-08T19:30:00-01:00",
        "endDate": "2019-05-08T23:00:00-01:00",
        "location": {
        "@type": "Place",
        "name": "AT&T Park",
        "address": {
        "@type": "PostalAddress",
        "streetAddress": "AT&T Park",
        "addressLocality": "San Francisco",
        "addressRegion": "CA",
        "postalCode": "94107",
        "addressCountry": "US"
        }
        }
        },
        "ticketToken": "qrCode:AB34",
        "ticketNumber": "abc123",
        "numSeats": "1",
        "modifiedTime": "2019-05-07T15:15:00-01:00",
        "modifyReservationUrl": "http://united.com/modifyreservation.html"
        }
    </script>

    <p>
        Dear Oscar, thanks for booking your Google I/O ticket with us.
    </p>
    <p>
        BOOKING DETAILS<br />
        Reservation number: IO12345<br />
        Order for: Oscar Andersson<br />
        Event: Google I/O 2013<br />
        Start time: May 15th 2013 8:00am PST<br />
        Venue: Moscone Center, 800 Howard St., San Francisco, CA 94103<br />
    </p>
</body>
</html>

我已使用Google的Email Markup Tester验证了标记,并说No errors detected。然后,我通过运行->通过Outlook发送,将上述HTML从Notepad ++导入到Outlook,并将其发送到我的Gmail。我收到了电子邮件,但是没有日历事件。

https://www.google.com/webmasters/markup-tester/

根据他们的文档All schemas you send to yourself (from x@gmail.com to x@gmail.com) will be displayed in Google products.,但我看不到该事件。

https://developers.google.com/gmail/markup/registering-with-google

我尝试创建自己的程序,以通过Gmail服务器向自己发送电子邮件,但事件仍然不显示。尝试复制其指南和参考页上提到的许多事件。

var emailAddress = new MailAddress("myGmail@gmail.com", "Ogglas");

SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("myGmail@gmail.com", "mySuperSecurePassword789&");

MailMessage mailMessage = new MailMessage();
mailMessage.From = emailAddress;
mailMessage.To.Add(emailAddress);
mailMessage.Subject = "Concert test";
mailMessage.IsBodyHtml = true;

var currentPath = Directory.GetCurrentDirectory();
var htmlEmail = File.ReadAllText(currentPath + "\\Email.html");
mailMessage.Body = htmlEmail;

smtpClient.Send(mailMessage);

一个航班的示例,我希望它看起来如何:

Gmail:

enter image description here

日历:

enter image description here

booking.com的示例

enter image description here

这里有没有人设法解决这个问题?

0 个答案:

没有答案