英文:
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日历中创建事件,您可以生成一个类似于以下链接的链接:
参数:
- 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.
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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论