I am failing to construct a MIME message that is displayed as a meeting invitation in Outlook, compared to when sending an invitation natively via Outlook.
What I want is this view (at least more or less):
What I get instead:
(The file displayed as .ics attachment can be opened and shows correct content).
Here's the meeting body (ics), that I construc programmatically:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:123
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VTIMEZONE
TZID:Europe/Amsterdam
BEGIN:STANDARD
TZOFFSETTO:+0100
TZOFFSETFROM:+0100
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=Europe/Amsterdam:20201214T085500
DTEND;TZID=Europe/Amsterdam:20201214T095500
SUMMARY:Test Event
LOCATION:skico HQ
DESCRIPTION:A test in appointment chatbot
PRIORITY:3
END:VEVENT
END:VCALENDAR
The MIME message is built via MimeKit:
private static string BuildMimeContent(Mail mail)
{
var textBody = new TextPart("plain") { Text = mail.BodyText };
var htmlBody = new TextPart("html") { Text = mail.BodyHtml };
var alternative = new Multipart("alternative");
alternative.Add(textBody);
alternative.Add(htmlBody);
var multiPart = new Multipart("mixed") { alternative };
if (mail.Event != null)
{
var eventBody = mail.Event.Parse();
var calendarBody = new TextPart("calendar")
{
Text = eventBody,
ContentTransferEncoding = ContentEncoding.Base64
};
calendarBody.ContentType.Parameters.Add("method", "REQUEST");
calendarBody.ContentType.Parameters.Add("name", "meeting.ics");
alternative.Add(calendarBody);
}
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress(mail.Sender.Name, mail.Sender.EMail));
mimeMessage.To.Add(new MailboxAddress(mail.Recipient.Name, mail.Recipient.EMail));
mimeMessage.Subject = mail.Subject;
mimeMessage.Body = multiPart;
// parse and return mime message
return mimeMessage.ToString();
}
yielding:
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-rdfmBTE1TuDNFI0Wzfmibg=="
--=-rdfmBTE1TuDNFI0Wzfmibg==
Content-Type: multipart/alternative; boundary="=-6bp3YWbl6STSnwQq7Fne2A=="
--=-6bp3YWbl6STSnwQq7Fne2A==
Content-Type: text/plain; charset=utf-8
Hi!
--=-6bp3YWbl6STSnwQq7Fne2A==
Content-Type: text/html; charset=utf-8
<strong>Hi!</strong>
--=-6bp3YWbl6STSnwQq7Fne2A==
Content-Type: text/calendar; charset=utf-8; method=REQUEST
Content-Id: <123#s.com>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Microsoft Corporation//Outlook 15.0 MIMEDIR//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VTIMEZONE
TZID:Europe/Amsterdam
BEGIN:STANDARD
TZOFFSETTO:+0100
TZOFFSETFROM:+0100
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=Europe/Amsterdam:20201214T120800
DTEND;TZID=Europe/Amsterdam:20201214T130800
SUMMARY:Test Event
LOCATION:skico HQ
DESCRIPTION:A test in appointment chatbot
PRIORITY:3
END:VEVENT
END:VCALENDAR
--=-6bp3YWbl6STSnwQq7Fne2A==--
--=-rdfmBTE1TuDNFI0Wzfmibg==--
How does the MIME content need to be constructed instead, such that the alternate view works in Outlook?
There was something wrong with my ICS content. This fixed it:
BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 15.0 MIMEDIR//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20201214T121600Z
DTEND:20201214T131600Z
SEQUENCE:0
UID:56b39b14ebb641ab7de716a62bed46aa
DTSTAMP:20201210T121600Z
LAST-MODIFIED:20201210T121600Z
SUMMARY:Test Event
LOCATION:s HQ
DESCRIPTION:A test in appointment chatbot
END:VEVENT
END:VCALENDAR
I did not track it down to the root cause. Probably the UID is madatory or the date/timezone format was invalid before.
Related
I've been hunting for this information for a week without any solid success.
I am targeting an Exchange 2010_SP2 server and have an application which sends out Appointments (Meetings) using EWS and inviting users/attendees. Currently when a user forwards their calendar item to another user, Exchange sends my application's email address an automatic notification about the forward. From the information contained within the notification message, I cannot find any information to help me specifically bind to the original appointment. I do have some clues with the user that forwarded it, the title of the event, and the date/time for it, but nothing that is guaranteed to be unique. I was thinking I could embed a unique identifier into the subject, but this seems a little gross. Has anyone else figured out a way to look up the event in context?
(Using C# and Microsoft's EWS Client API)
case EmailMessage fw when fw.ItemClass == "IPM.Schedule.Meeting.Notification.Forward":
EmailMessage message = EmailMessage.Bind(Global.Exchange, fw.Id);
message.Load();
I have attempted to try to query for the conversation, tried attaching customer X-Parameters to the original meeting, and have inspected all the properties I can think of within an EmailMessage object.
Example of a forward notification:
Internet Headers attached to the Email: (some parts redacted using ----)
Received: from FMSEDG002.ED.cps.----.com (10.1.192.134) by
fmsmsx121.amr.corp.----.com (10.18.125.36) with Microsoft SMTP Server (TLS)
id 14.3.439.0; Sat, 13 Jun 2020 14:24:33 -0700
Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.36.54) by
edgegateway.----.com (192.55.55.69) with Microsoft SMTP Server (TLS) id
14.3.439.0; Sat, 13 Jun 2020 14:24:33 -0700
Received: from BYAPR11MB3830.namprd11.prod.outlook.com (2603:10b6:a03:fc::14)
by BYAPR11MB3797.namprd11.prod.outlook.com (2603:10b6:a03:fe::27) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.22; Sat, 13 Jun
2020 21:24:30 +0000
Received: from BYAPR11MB3830.namprd11.prod.outlook.com
([fe80::9d21:2f25:9b76:e341]) by BYAPR11MB3830.namprd11.prod.outlook.com
([fe80::9d21:2f25:9b76:e341%7]) with mapi id 15.20.3088.027; Sat, 13 Jun 2020
21:24:30 +0000
Content-Type: multipart/mixed;
boundary="_000_BYAPR11MB383088E85E5BF51D212384F4F99E0BYAPR11MB3830namp_"
From: ----
To: ----
Subject: Meeting Forward Notification: Dummy Event - Example 3
Thread-Topic: Meeting Forward Notification: Dummy Event - Example
3
Sender: Microsoft Outlook
<MicrosoftExchange32----#----.onmicrosoft.com>
Date: Sat, 13 Jun 2020 21:24:30 +0000
Message-ID: <BYAPR11MB383088E85E5BF51D212384F4F99E0#BYAPR11MB3830.namprd11.prod.outlook.com>
X-MS-Has-Attach:
X-MS-TNEF-Correlator: <BYAPR11MB383088E85E5BF51D212384F4F99E0#BYAPR11MB3830.namprd11.prod.outlook.com>
authentication-results: ----; dkim=none (message not signed)
header.d=none;----; dmarc=none action=none header.from=----;
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: 53ede74f-9111-4b3f-01ff-08d80fe028c7
x-ms-traffictypediagnostic: BYAPR11MB3797:
x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr
x-ms-oob-tlc-oobclassifiers: OLM:2089;
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: bevNkvUhwfDB1JTruSgvhewEnlseaRPl5vEl4tx04MJVY/bY7tbeShWgjWHsg2ZEGmWH2ZZN2rjA4NjqI9seC5ei1B9A0m8tvCr7Ij+3IJAUr8vYz0F7LRwVKE2nZB1E7Wy7V3pHvYxyT6tyOvjbxDeHN7Fbs0dvKYwj4g/EWxAEiXNmGFxkPXGowV3I1v2vWT+hBIIO6Sz1Lg8/jzPm7l6d9DZZ7gxjQDQfuAcBgQEUj46RqNlMosWGEK65oBHWTYRC4R2oc3z2qS3Y8VgIzg==
x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:-1;SRV:;IPV:NLI;SFV:SKI;H:BYAPR11MB3830.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:INB;SFP:;
x-ms-exchange-transport-forked: True
MIME-Version: 1.0
X-MS-Exchange-CrossTenant-Network-Message-Id: 53ede74f-9111-4b3f-01ff-08d80fe028c7
X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2020 21:24:30.0788
(UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3797
X-OrganizationHeadersPreserved: BYAPR11MB3797.namprd11.prod.outlook.com
Return-Path: <>
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 04
X-MS-Exchange-Organization-AuthSource: BYAPR11MB3830.namprd11.prod.outlook.com
X-CrossPremisesHeadersPromoted: ----
X-CrossPremisesHeadersFiltered: ----
X-MS-Exchange-Organization-SCL: -1
X-OriginatorOrg: intel.onmicrosoft.com
X-MS-Exchange-Organization-AVStamp-Mailbox: NAI;60104903;0;novirus
The PidLidCleanGlobalObjectId http://msdn.microsoft.com/en-us/library/cc839502.aspx extended should be set on the notification. You can use that to search for the Appointment eg this is on example of using that property
Appointment newAppointment = new Appointment(service);
newAppointment.Subject = "Test Subject";
newAppointment.Start = new DateTime(2016, 08, 27, 17, 00, 0);
newAppointment.StartTimeZone = TimeZoneInfo.Local;
newAppointment.EndTimeZone = TimeZoneInfo.Local;
newAppointment.End = newAppointment.Start.AddMinutes(30);
newAppointment.Save();
newAppointment.Body = new MessageBody(Microsoft.Exchange.WebServices.Data.BodyType.Text, "test");
newAppointment.RequiredAttendees.Add("attendee#domain.com");
newAppointment.Update(ConflictResolutionMode.AlwaysOverwrite ,SendInvitationsOrCancellationsMode.SendOnlyToAll);
ExtendedPropertyDefinition CleanGlobalObjectId = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, 0x23, MapiPropertyType.Binary);
PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
psPropSet.Add(CleanGlobalObjectId);
newAppointment.Load(psPropSet);
object CalIdVal = null;
newAppointment.TryGetProperty(CleanGlobalObjectId, out CalIdVal);
Folder AtndCalendar = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar,"attendee#domain.com"));
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(CleanGlobalObjectId, Convert.ToBase64String((Byte[])CalIdVal));
ItemView ivItemView = new ItemView(1);
FindItemsResults<Item> fiResults = AtndCalendar.FindItems(sfSearchFilter, ivItemView);
if (fiResults.Items.Count > 0) {
//do whatever
}
When I want to send message to outlook.com e-mail address, then it's going to spam/junk folder, while it's OK for Google and Yahoo mail. I've checked SpamAssassin scores for all these mail providers (I've used https://spamcheck.postmarkapp.com/):
Google: 1.7, Good
1.5 RCVD_IN_SORBS_WEB (I'm on one blacklist)
Yahoo: 1.5, Good
1.5 RCVD_IN_SORBS_WEB (the same - I'm on one blacklist. The rest is OK!)
Outlook: 5.7, Spam!
0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was
blocked. See
http://wiki.apache.org/spamassassin/DnsBlocklists…
#dnsbl-block for more information. [URIs:x]
1.2 MISSING_HEADERS Missing To: header
0.1 DKIM_SIGNED Message has a DKIM or DK signature, not
necessarily valid
0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid
0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines
1.4 MISSING_DATE Missing Date: header
1.0 MISSING_FROM Missing From: header
0.1 MISSING_MID Missing Message-Id: header
1.8 MISSING_SUBJECT Missing Subject: header
0.0 TVD_SPACE_RATIO No description available.
GMX: 4, Good (well, it's in spam folder!)
-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no
trust [ listed in list.dnswl.org]
0.1 DKIM_SIGNED Message has a DKIM or DK signature, not
necessarily valid
0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid
1.3 RDNS_NONE Delivered to internal network by a host with no
rDNS
2.3 EMPTY_MESSAGE Message appears to have no textual parts and no
Subject: text
0.1 MISSING_MID Missing Message-Id: header
As you can see there're missing headers, but it was OK in Google and Yahoo. Here is my code (C#)
MailMessage mail = new MailMessage(username, mailReceiver);
mail.Subject = title;
AddAlternativeTextViewToMail(ref mail, message); // adding alternative view to HTML one (plain text)
SmtpClient client = new SmtpClient();
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.UseDefaultCredentials = false;
client.Host = "mail.mydomain.com";
client.Credentials = new NetworkCredential(username, password);
//mail.Body = message; // no body, coz it's already in alternative view
client.Send(mail);
Here is AddAlternativeTextViewToMail method:
private static void AddAlternativeTextViewToMail(ref MailMessage mail, string message)
{
string htmlTagPattern = "<[^\"]*?>";
string plainMessage = message.Replace("<br />", "\r\n");
plainMessage = Regex.Replace(plainMessage, htmlTagPattern, string.Empty);
plainMessage = plainMessage.Replace("<", "").Replace(">", "").Replace("a target=\"_blank\" href=\"", " ").Replace("\"", " ").Replace("a href=", "");
//plainMessage = Regex.Replace(plainMessage, #"^\s+$[\r\n]*", "", RegexOptions.Multiline);
//plainMessage = plainMessage.Replace(" ", string.Empty);
mail.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(plainMessage, Encoding.UTF8, System.Net.Mime.MediaTypeNames.Text.Plain));
mail.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(message, Encoding.UTF8, System.Net.Mime.MediaTypeNames.Text.Html));
}
Also if I send the same e-mail from Google mail, then it is not going to spam folder in Outlook. What am I doing wrong?
Cheers
I have a requirement to send the meeting request with html body Tag.I have successfully send the meeting request it work perfectly.
Here is the ICS file format
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//A//B//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
ORGANIZER;CN="Organizer":mailto:#FROM#
ATTENDEE;CN="Attendee";CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=
NEEDS-ACTION;RSVP=TRUE:mailto:#TO#
DTSTART:#DTSTART#
DTEND:#DTEND#
LOCATION:#LOCATION#
SUMMARY: Invitation for Meeting
TRANSP:OPAQUE
SEQUENCE:0
UID:#UID#
DTSTAMP:#CREATED-AT#
CREATED:#CREATED-AT#
LAST-MODIFIED:#CREATED-AT#
DESCRIPTION: #DESCRIPTION#
X-ALT-DESC;FMTTYPE=text/html: #X-ALT-DESC#
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
I found some link to send the html link wiht X-ALT-DESC option but it not work for me
Send an Outlook Meeting Request with C#
Send an Outlook Meeting Request with C#
Send email to Outlook with ics meeting appointment
Send email to Outlook with ics meeting appointment
Here is the C# code to send the email with ICS file
filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "Email/calenderInvitation.ics");
fileContent = System.IO.File.OpenText(filePath).ReadToEnd();
fileContent = fileContent.Replace("#TO#", receiver);
fileContent = fileContent.Replace("#FROM#", fromAddress.Address);
fileContent = fileContent.Replace("#LOCATION#", eventVenue);
fileContent = fileContent.Replace("#UID#", Guid.NewGuid().ToString().Replace("-", ""));
fileContent = fileContent.Replace("#CREATED-AT#", Convert.ToDateTime(meetingDate).ToString(TimeFormat));
fileContent = fileContent.Replace("#DTSTART#", Convert.ToDateTime(startTime).ToString(TimeFormat));
fileContent = fileContent.Replace("#DTEND#", Convert.ToDateTime(finishTime).ToString(TimeFormat));
filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "Email/InvitationEmail.html");
fileInviationContent = System.IO.File.OpenText(filePath).ReadToEnd();
String body = AppendRedirectURl(fileInviationContent, callBackUrl);
fileContent = fileContent.Replace("#X-ALT-DESC#", body);
MailMessage message = new MailMessage();
// message.IsBodyHtml = true;
message.From = new MailAddress(fromAddress.Address);
message.To.Add(new MailAddress(receiver));
message.Subject = string.Format("{0} {1} # {2} {3} {4} {5} - {6}", "Invitation: ", meetingTypeName,
Convert.ToDateTime(meetingDate).ToString("dddd"), Convert.ToDateTime(startTime).ToString("MMMM"),
Convert.ToDateTime(startTime).ToString("yyyy"), startTime,
finishTime);
var iCalendarContentType = new ContentType("text/calendar; method=REQUEST");
var calendarView = AlternateView.CreateAlternateViewFromString(fileContent, iCalendarContentType);
calendarView.TransferEncoding = TransferEncoding.SevenBit;
message.AlternateViews.Add(calendarView);
await smtp.SendMailAsync(message);
Here is the Debugger response
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//A//B//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
ORGANIZER;CN="Organizer":mailto:admin#wordflow.info
ATTENDEE;CN="Attendee";CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=
NEEDS-ACTION;RSVP=TRUE:mailto:anandjaisy#gmail.com
DTSTART:20171206T081500Z
DTEND:20171206T090000Z
LOCATION:asdasd
SUMMARY: Invitation for Meeting
TRANSP:OPAQUE
SEQUENCE:0
UID:b17f15326c5343ff98d76bf6092ed2b4
DTSTAMP:20171212T000000Z
CREATED:20171212T000000Z
LAST-MODIFIED:20171212T000000Z
DESCRIPTION: #DESCRIPTION#
X-ALT-DESC;FMTTYPE=text/html: <html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<br><br><br>
<form class="container">
<div class="form-group">
<label>Click on Accept or Decline to add event to your Email Calender </label>
</div>
<div class="form-group">
<label>Will you Attend the Meeting</label>
Yes
No
</div>
<div class="form-group text-center">
</div>
</form>
</body>
</html>
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
It send the invitation but body is not been send
I found the solution at this link (visual basic) https://social.msdn.microsoft.com/Forums/en-US/2cd0dcff-7d6c-493e-bf49-87a3e3248d01/create-meeting-request-with-html-body-in-aspnet?forum=netfxnetcom
Basically, you add a second AlternateView. Below is how I did it. My "body" string has my html. I did notice that my meeting was broken in Outlook if I add "avCalendar" before "avHtmlBody". So I guess the order matters.
In my meetingRequestString, I removed the parts for DESCRIPTION and X-ALT-DESC.
MailMessage msg = new MailMessage(from, to);
var htmlContentType = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Html);
var avHtmlBody = AlternateView.CreateAlternateViewFromString(body, htmlContentType);
msg.AlternateViews.Add(avHtmlBody);
string meetingRequestString = GetMeetingRequestString(from, to, subject, body, startTime, endTime);
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
ct.Parameters.Add("name", "meeting.ics");
AlternateView avCalendar = AlternateView.CreateAlternateViewFromString(meetingRequestString, ct);
msg.AlternateViews.Add(avCalendar);
client.Send(msg);
I am trying to send an Meeting Invite with C# and for some reason it will not be sent if the Organizer's email address has a period.
ORGANIZER;CN="John, Song":mailto:song.john#company.com
It will work if I remove the period in the email address
ORGANIZER;CN="John, Song":mailto:songjohn#company.com
My complete sample code is here.
public static void SendEmailString()
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("song#company.com", "Song");
msg.To.Add(new MailAddress("John#company.com", "John"));
msg.Subject = "CS Inquiry";
msg.Body = "TESTING";
string test = #"BEGIN:VCALENDAR
PRODID: -//Company & Com//Credit Inquiry//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VEVENT
ATTENDEE;CN=""John, Song"";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:song#company.com
ATTENDEE;CN=""Lay, Sean"";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:lins#company.com
ORGANIZER;CN="John, Song":mailto:song.john#company.com
DTSTART:20171205T040000Z
DTEND:20171206T040000Z
LOCATION:New York
TRANSP:TRANSPARENT
SEQUENCE:0
UID:a16fbc2b-72fd-487f-adee-370dc349a2273asfdasd
DTSTAMP:20171027T215051Z
DESCRIPTION:Request for information regarding Test
SUMMARY:Summary
PRIORITY: 5
CLASS: PUBLIC
BEGIN:VALARM
TRIGGER:-PT1440M
ACTION: DISPLAY
DESCRIPTION:REMINDER
END:VALARM
END:VEVENT
END:VCALENDAR
";
SmtpClient sc = new SmtpClient("smtp.company.com");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(test, ct);
msg.AlternateViews.Add(avCal);
sc.Send(msg);
}
Anyone know why this is happening? I looked at the iCalendar spec and couldn't find anything about period being an illegal character in Organizer's email address.
Thanks!
I have an email application that creates encrypted emails. It works fine in outlook and all the email counterparties I send the email to reports no issues.
However when I try to decrypt them with Mimekit I get a "Bad data" exception.
Some of the stack trace:
at System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent(RecipientInfoCollection recipientInfos, X509Certificate2Collection extraStore)
at System.Security.Cryptography.Pkcs.EnvelopedCms.Decrypt()
at MimeKit.Cryptography.WindowsSecure...
My email mime looks like this:
Received: from Dx ([x]) by
x ([x]) with mapi id
x; Fri, 7 Mar 2014 14:48:49 +0100
From: x <x#x.com>
To: x <x2#x.com>
Subject:
xxxxxxxx
07-03-2014 14:48:46
Thread-Topic:
xxxxxxx
07-03-2014 14:48:46
Thread-Index: AQHPOgv3JHiUE6wuJk+EQu4eAA1oDA==
Date: Fri, 7 Mar 2014 14:48:48 +0100
Message-ID: <x>
Accept-Language: da-DK, en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: x
X-MS-Exchange-Organization-AuthMechanism: x
X-MS-Exchange-Organization-AuthSource: x
X-MS-Has-Attach: yes
X-MS-Exchange-Organization-SCL: -1
X-MS-TNEF-Correlator:
Content-Type: application/pkcs7-mime; name="smime.p7m";
smime-type=enveloped-data
Content-Disposition: attachment; filename="smime.p7m"
Content-Transfer-Encoding: base64
MIME-Version: 1.0
MIIeOgYJKoZIhvcNAQcDoIIeKzCCHicCAQAxggLnMIIC4wIBADCByjCBxDEfMB0GA1UEChMWRGFu
c2tlIENvbW1vZGl0aWVzIEEvUzEaMBgGA1UECxMRQnVzaW5lc3MgU29mdHdhcmUxNTAzBgkqhkiG
9w0BCQEWJmJ1c2luZXNzY2xlYXJpbmdAZGFuc2tlY29tbW9kaXRpZXMuY29tMQ8wDQYDVQQHEwZB
YXJodXMxEDAOBgNVBAgTB0Rlbm1hcmsxCzAJBgNVBA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TBWeecEoWaIobMNYvTD3xbSzx6SH+20T59rdR8p0mJB
ECVc0pl3QQugE5w0Qrp7/CJ2Pxrmcc7tCWdnVOjglp3JcUBL2ZRJeQBPk5Bm6OCczR+sviFux2Me
MF/3E7TSRspBPscL9XHHH8eBznnjZ8fJAu0YAhTGjzL1DOjjVZ9KNlxWwGG+mCALm+XU8DpJNKg9
Nuq2uYSRu4p5K4+lEAyRM2cdiPLVcDuGKQpBGQnhsB6DslLImiYXSzy6OcHIsUf4kyAGes5tsBxR
i1IfNHcW4G/7i4VUy+530PqA0+TECNkpgiGxrevWk0gF0NgD+DDNgDzZRjJaRpMx0ufbP9twVvv+
6J/meqKiykYcU/NUYV/TuNiERKrOOWZs697IyY/g3nPWHZurZXJbmk9MpND2wn5PZzRTx7qyBVfn
nenl/WtSVMmKA4D1dLnHoeN1hoAyQgrfqS4yymL26UemhCXIV87hAYwwoAbpfr4=
This is how I perform my encryption:
public static string EncryptContent(string content, X509Certificate2 certificate)
{
byte[] contentBytes = Encoding.ASCII.GetBytes(content);
var envelopedCms = new EnvelopedCms(SubjectIdentifierType.IssuerAndSerialNumber, new ContentInfo(contentBytes));
var recipient = new CmsRecipient(SubjectIdentifierType.IssuerAndSerialNumber, certificate);
envelopedCms.Encrypt(recipient);
var encodedData = envelopedCms.Encode();
var encodedDataBase64 = Convert.ToBase64String(encodedData, Base64FormattingOptions.InsertLineBreaks);
return encodedDataBase64;
}
and this is how I attempt to decrypt:
var primarySecureMimeContext = CreateSecureMimeContext(certificateInfo.PrimaryCertificate,
certificateInfo.PrimaryPassword);
var primaryDecryptedEntity = entity.Decrypt(primarySecureMimeContext);
private SecureMimeContext CreateSecureMimeContext(string certificateFilename, string certificatePassword)
{
var secureMimeContext = new WindowsSecureMimeContext();
var certificate = new X509Certificate2(certificateFilename,
certificatePassword);
var bouncyX509Certificate = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate(certificate);
secureMimeContext.Import(bouncyX509Certificate);
return secureMimeContext;
}
When I decrypt the content myself using enveloped cms directly, there are no issues.
This is the email after my own decryption:
Content-Type: multipart/mixed;
boundary="5511bd79-26dc-41e5-ac96-7adfdea5f6e5"
--5511bd79-26dc-41e5-ac96-7adfdea5f6e5
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
--5511bd79-26dc-41e5-ac96-7adfdea5f6e5
Content-Type: application/octet-stream;
name="TestFile.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="TestFile.txt"
77u/VGVlZWVlZXN0
--5511bd79-26dc-41e5-ac96-7adfdea5f6e5--
Can anyone see what is causing this?
After having using the DummySecureMimeContext as proposed by jstedfast it works. A more thorough walkthrough can be found here: https://github.com/jstedfast/MimeKit/issues/38
I think the problem is the way you are adding the certificate to the context:
private SecureMimeContext CreateSecureMimeContext(string certificateFilename, string certificatePassword)
{
var secureMimeContext = new WindowsSecureMimeContext();
var certificate = new X509Certificate2(certificateFilename,
certificatePassword);
var bouncyX509Certificate = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate(certificate);
secureMimeContext.Import(bouncyX509Certificate);
return secureMimeContext;
}
What this is doing is adding the certificate to the AddressBook certificate store, but where you actually want to add it in order to decrypt it (because you'll need the private key password as well) is the personal cert store.
Try this:
private SecureMimeContext CreateSecureMimeContext (string certificateFilename, string certificatePassword)
{
var secureMimeContext = new WindowsSecureMimeContext ();
using (var stream = File.OpenRead (certificateFilename))
secureMimeContext.Import (stream, certificatePassword);
return secureMimeContext;
}
The exception message you are getting isn't very helpful, but I am guessing that it means that it can't find the certificate and/or private key. I wrote a test program and have been unsuccessful in reproducing this bug, so I could be wrong... but since my certificates/private keys are already imported into my personal cert store, I'm not sure how to remove them to test this theory.
Let me know how that works out for you.
Update: Oops, I done goofed. Just updated CreateSecureMimeContext() above to open the certificate file stream because WindowsSecureMimeContext.Import() takes a stream, not a file name.