如何在C#中使用Sendgrid发送日历邀请?
我可以将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");
答案 0 :(得分:0)
如果您要发送日历,则需要执行以下操作:
// 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
答案 1 :(得分:0)
一些事情。
首先,CalendarContent看起来没有效果,它没有任何换行符。
首先尝试:
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";
如果这不起作用,看来以下内容并不遵循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
可能是:
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
答案 2 :(得分:0)
试试这个
//创建日历字符串
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");