ICS文件通过C#按钮在Gmail中打开

huangapple go评论64阅读模式
英文:

ICS file to open in gmail through button C#

问题

我正在尝试生成一个ICS文件,该文件作为附件包含在我的电子邮件中。我想在该电子邮件中添加一个按钮,当点击时,会将我们带到Gmail(可能会要求输入Gmail用户名,以便将事件添加到Gmail日历中)。我找不到类似的东西。有人可以帮助吗?

StringBuilder sb = new StringBuilder();
sb.AppendLine("BEGIN:VCALENDAR");
sb.AppendLine("VERSION:2.0");
sb.AppendLine("PRODID:Domain.com");
sb.AppendLine("CALSCALE:GREGORIAN");
sb.AppendLine("METHOD:REQUEST");
sb.AppendLine("BEGIN:VEVENT");
sb.AppendLine("UID:" + guid);
sb.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", retailStore.LocationEmail));
sb.AppendLine(string.Format("ATTENDEE;CN='{0}, {1}';ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE:MAILTO:{2}", CustomerFirstName, CustomerLastName, CustomerEmail));
sb.AppendLine("DTSTART:" + DateStart.ToUniversalTime().ToString(DateFormat));
sb.AppendLine("DTSTAMP:" + now);
sb.AppendLine("SUMMARY: " + Summary);
sb.AppendLine("LOCATION: " + Location);
sb.AppendLine("DESCRIPTION:" + Description);
sb.AppendLine("PRIORITY:5");
sb.AppendLine("TRANSP:OPAQUE");
sb.AppendLine("END:VEVENT");
sb.AppendLine("END:VCALENDAR");

var calendarBytes = Encoding.UTF8.GetBytes(sb.ToString());
System.IO.MemoryStream stream = new System.IO.MemoryStream(calendarBytes);
Attachment attachment = new Attachment(stream, FileName, "text/calendar");
customerMailMessage.Attachments.Add(attachment);

希望这对你有所帮助。如果你有任何其他问题,请随时提问。

英文:

I am trying to generate an ICS file which is coming as an attachment to my email. I want to add a button to that email which, when clicked takes us to gmail (may be ask username for gmail where we need to add the event) and add it to the gmail calendar. I m not able to find anything of this sort. Can anyone help

    StringBuilder sb = new StringBuilder();
    sb.AppendLine("BEGIN:VCALENDAR");
    sb.AppendLine("VERSION:2.0");
    sb.AppendLine("PRODID:Domain.com");
    sb.AppendLine("CALSCALE:GREGORIAN");
    sb.AppendLine("METHOD:REQUEST");
    sb.AppendLine("BEGIN:VEVENT");
    sb.AppendLine("UID:" + guid);
    sb.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", retailStore.LocationEmail));
    sb.AppendLine(string.Format("ATTENDEE;CN='{0}, {1}';ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE:MAILTO:{2}", CustomerFirstName, CustomerLastName, CustomerEmail));
    sb.AppendLine("DTSTART:" + DateStart.ToUniversalTime().ToString(DateFormat));
    sb.AppendLine("DTSTAMP:" + now);
    sb.AppendLine("SUMMARY: " + Summary);
    sb.AppendLine("LOCATION: " + Location);
    sb.AppendLine("DESCRIPTION:" + Description);
    sb.AppendLine("PRIORITY:5");
    sb.AppendLine("TRANSP:OPAQUE");
    sb.AppendLine("END:VEVENT");
    sb.AppendLine("END:VCALENDAR");

    var calendarBytes = Encoding.UTF8.GetBytes(sb.ToString());
    System.IO.MemoryStream stream = new System.IO.MemoryStream(calendarBytes);
    Attachment attachment = new Attachment(stream, FileName, "text/calendar");
    customerMailMessage.Attachments.Add(attachment);

答案1

得分: 1

如果消息接收者使用Gmail,当ICS文件在其收件箱中正确创建时,他们将看到一个选项来添加事件。

其他电子邮件客户端可能(但不总是)也支持这一功能,但接收者的体验可能会有所不同,事件可能会保存在除Google之外的其他日历中,这取决于用户的配置。

如果您想包括一个按钮以在Google日历中创建事件,您可以生成一个类似于以下链接的链接:

https://www.google.com/calendar/render?action=TEMPLATE&text=MyEvent&details=Description&location=London&dates=20230719T205300Z%2F20230720T205300Z&add=you@example.com

参数:

  • text:事件名称
  • details:事件描述
  • location:事件地点
  • dates:开始和结束日期以ISO 8601格式(以%2F字符分隔的格式)(HTML编码中的/
  • add:事件嘉宾的电子邮件地址

所有参数都是可选的,用户必须确认事件。他们将成为组织者,可以删除您,更改所有设置等。

请记住,此链接与您正在创建的ICS文件没有任何关系!

英文:

If the message recipient is using Gmail, they will see an option to add the event when the ICS file is correctly created in their inbox.

ICS文件通过C#按钮在Gmail中打开

Other email clients may (but not always) support this as well, but the experience for the recipient may vary, and the event may be saved in a calendar other than Google, depending on the user's configuration.

If you want to include a button to create the event in Google Calendar, you can generate a link like this:

https://www.google.com/calendar/render?action=TEMPLATE&text=MyEvent&details=Description&location=London&dates=20230719T205300Z%2F20230720T205300Z&add=you@example.com

Parameters:

  • text: event name
  • details: event description
  • location: event location
  • dates: start and end date in ISO 8601 format (separated by the %2F character [/ in HTML encoding])
  • add: email address of the event guest

All parameters are optional, and the user will have to confirm the event themselves. They will be the organizer and can remove you, change all settings, etc.

Remember, this link is not in any way related to the ICS file you are creating!

huangapple
  • 本文由 发表于 2023年7月17日 23:09:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76705829.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定