[英]Attach ics file in Sendgrid
How to send Calendar Invite using Sendgrid in C#? 如何在C#中使用Sendgrid发送Calendar Invite?
I am able to attach the ics file to the mail, but when I download the attachement I get the error as "Invalid Calendar File". 我可以将ics文件附加到邮件中,但是当我下载附件时,收到的错误消息为“无效的日历文件”。
string CalendarContent = "BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Meeter/meeter//NONSGML v1.0//EN CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VEVENT DTSTART:20141018T203000Z DTEND:20141018T210000Z UID:20141015T002813-223788868@meeter.com DTSTAMP:20141014T212813Z ORGANIZER;CN=\"snaggs@gmail.com\";SENT-BY=\"MAILTO:someapp@gmail.com\";LANGUAGE=se:MAILTO:snaggs@gmail.com ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Fessy M;X-NUM-GUESTS=0:MAILTO:snaggs2@gmail.com DESCRIPTION:dddd mandrill LOCATION:dddddd mandrill SUMMARY:Can I lay low? Cook some yay-yo 2 TRANSP:OPAQUE SEQUENCE:0 STATUS:CONFIRMED END:VEVENT END:VCALENDAR";
using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(CalendarContent )))
{
_Message.AddAttachment(ms, "meeting.ics");
}
var Header = new Dictionary<string, string>();
Header.Add("Content-Type", "text/calendar");
If you are trying to send a calendar you will need to do the following: 如果您要发送日历,则需要执行以下操作:
// you already have the _Message & CalendarContent created above
// first thing, convert calendar content to byte array and then stream
byte[] calendarBytes = Encoding.UTF8.GetBytes(CalendarContent.ToString());
Stream calendarStream = new MemoryStream(calendarBytes);
// them create a attachment for your mail message
Attachment calendarAttachment = new Attachment(calendarStream, "calendar.ics", "text/calendar");
calendarAttachment.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
// now attach the calendar to your Mail Message
_Message.Attachments.Add(calendarAttachment);
// now send the message off
A few things. 一些东西。
First you CalendarContent doesn't look valid, it doesn't have any line breaks in it. 首先,CalendarContent看起来无效,其中没有任何换行符。
First try: 第一次尝试:
string CalendarContent = @"BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Meeter/meeter//NONSGML v1.0//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20141018T203000Z
DTEND:20141018T210000Z
UID:20141015T002813-223788868@meeter.com
DTSTAMP:20141014T212813Z
ORGANIZER;CN=\"snaggs@gmail.com\";SENT-BY=\"MAILTO:someapp@gmail.com\";LANGUAGE=se:MAILTO:snaggs@gmail.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Fessy M;X-NUM-GUESTS=0:MAILTO:snaggs2@gmail.com
DESCRIPTION:dddd mandrill
LOCATION:dddddd mandrill
SUMMARY:Can I lay low? Cook some yay-yo 2
TRANSP:OPAQUE
SEQUENCE:0
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR";
If that doesn't work, it appears the following doesn't follow RFC 5545 but I'm not positive about this, the RFC can be confusing: 如果这不起作用,则可能是以下内容未遵循RFC 5545,但我对此并不满意 ,RFC可能会造成混淆:
ORGANIZER;CN=\"snaggs@gmail.com\";SENT-BY=\"MAILTO:someapp@gmail.com\";LANGUAGE=se:MAILTO:snaggs@gmail.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Fessy M;X-NUM-GUESTS=0:MAILTO:snaggs2@gmail.com
might be: 可能:
ORGANIZER;LANGUAGE=se:SENT-BY=\"mailto:someapp@gmail.com\":mailto:snaggs@gmail.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Fessy M;X-NUM-GUESTS=0:mailto:snaggs2@gmail.com
Try this 尝试这个
// Create your calendar string //创建日历字符串
string lsCalendar = CreateCalendar(loMessage, fsUID, fdtStartDateTime, fdtEndDateTime, fdtTimeStamp, fsTimeZone, fsLocation, fsRecurType, fsWeekdays, fsAction);
byte[] calendarBytes = Encoding.UTF8.GetBytes(lsCalendar.ToString());
Stream calendarStream = new MemoryStream(calendarBytes);
loMessage.AddAttachment(calendarStream, "invite.ics");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.