1

I am working on service where I want to send emails with attachments(image, pdf, docs) and ics calendar invitation as an alternateview. Whenever I am sending mail with attachments the ics calendar invitation is missing in a mail but when I don't have any attachments in mail then I am able to receive calendar invitation.

Here is my code

if (Convert.ToString(DR["ATTACHMENT"]) != "")   //mail_att
{
    message.Attachments.Add(new Attachment(DR["ATTACHMENT"].ToString()));
}
if (Convert.ToString(DR["SCRIPT"]) != "")   //Mail_Sub
{
    System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
    ct.Parameters.Add("method", "REQUEST");
    ct.Parameters.Add("name", "meeting.ics");
    AlternateView avCal = AlternateView.CreateAlternateViewFromString(Convert.ToString(DR["SCRIPT"]), ct);
    message.AlternateViews.Add(avCal);
}

MailMessage object message is showing Attachments and AlternateView counts, still calendar invite is missing in mails whenever I add attachments.

Shreyas Pednekar
  • 1,285
  • 5
  • 31
  • 53

2 Answers2

0

Take a look on topic Send email to Outlook with ics meeting appointment

// Now Contruct the ICS file using string builder
StringBuilder str = new StringBuilder();
str.AppendLine("BEGIN:VCALENDAR");
str.AppendLine("PRODID:-//Schedule a Meeting");
str.AppendLine("VERSION:2.0");
str.AppendLine("METHOD:REQUEST");
str.AppendLine("BEGIN:VEVENT");
str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddMinutes(+330)));
str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddMinutes(+660)));
str.AppendLine("LOCATION: " + this.Location);
str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
str.AppendLine(string.Format("DESCRIPTION:{0}", msg.Body));
str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body));
str.AppendLine(string.Format("SUMMARY:{0}", msg.Subject));
str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", msg.From.Address));

str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[0].DisplayName, msg.To[0].Address));

str.AppendLine("BEGIN:VALARM");
str.AppendLine("TRIGGER:-PT15M");
str.AppendLine("ACTION:DISPLAY");
str.AppendLine("DESCRIPTION:Reminder");
str.AppendLine("END:VALARM");
str.AppendLine("END:VEVENT");
str.AppendLine("END:VCALENDAR");
integer
  • 221
  • 4
  • 13
0

If you are sending using straight SMTP, the attachments must be embedded inside the VEVENT part in an ATTACH field:

ATTACH;ENCODING=BASE64;VALUE=BINARY;X-FILENAME=test.txt:NBIBANyGrhFvX6xL...

Create an appointment with an attachment in Outlook and save it as an ICS file from Outlook as a test then open that ICS file in notepad then you can check how the script looks like, makes changes in your AlternateView calendar script

Shreyas Pednekar
  • 1,285
  • 5
  • 31
  • 53