JRawlins
Fri Jun 09 10:39:02 CDT 2006
Jeffery,
Thanks for keeping with this. I already have a working solution with CDO,
ADO and CAPICOM so I guess I will have to wait until the 3.0 framework?? Do
you know if there are plans to support SMIME moving forward? How else in a
Managed environment are we going to Digitally sign emails??
Again, thanks for your time and dedication to my problem..
Jason
""Jeffrey Tan[MSFT]"" wrote:
> Hi Jason,
>
> Sorry for letting you wait for so long.
>
> With a lot of discussion and researching with our another support team
> engineer, we are unfortunately to find that the scenario for supporting
> S/MIME messages was not designed into System.Net.Mail in .Net2.0.
>
> Currently, we have written a sample code snippet with CDO in .Net managed
> code snippet below, for your information:
> =================================Code
> snnipet====================================
> CDO.Message msg2 = new CDO.MessageClass();
> msg2.From = "winson.c.chan@intel.com";
> msg2.To = "winson.c.chan@intel.com";
> msg2.Subject = "Secure Mail Test";
> ================= 1==================
> ADODB.Stream stream2 = msg2.BodyPart.GetEncodedContentStream();
> stream2.Type = ADODB.StreamTypeEnum.adTypeBinary;
> byte[] message = System.Text.UTF8Encoding.UTF8.GetBytes("Can you read
> this?");
> stream2.Write(message);
> stream2.Flush();
> stream2.Close();
> =================2======================
> CDO.Message msg = new CDO.MessageClass();
> msg.From = "winson.c.chan@intel.com";
> msg.To = "winson.c.chan@intel.com";
> msg.Subject = "Secure Mail Test";
> msg.Configuration = new CDO.ConfigurationClass();
> msg.Configuration.Fields[@"
http://schemas.microsoft.com/cdo/configuration/se
> ndusing"].Value = 2;
> msg.Configuration.Fields[@"
http://schemas.microsoft.com/cdo/configuration/sm
> tpserver"].Value = "myserver";
> msg.Configuration.Fields.Update();
> ====================3================================
> msg.BodyPart.ContentMediaType = "application/pkcs7-mime; name=smime.p7m;
> smime-type=enveloped-data;";
> msg.BodyPart.ContentTransferEncoding = "base64";
> msg.BodyPart.Fields.Append("urn:schemas:mailheader:content-disposition",
> DataTypeEnum.adVarChar, 255, FieldAttributeEnum.adFldUpdatable,
> "attachment; filename=smime.p7m");
> msg.BodyPart.Fields.Update();
> =======================4====================================
> string strContent = msg2.GetStream().ReadText(msg2.GetStream().Size);
> byte[] pbBytes = System.Text.UTF8Encoding.UTF8.GetBytes(strContent);
> GCHandle GCBytes = GCHandle.Alloc(pbBytes, GCHandleType.Pinned);
> IntPtr ptrBytes = GCBytes.AddrOfPinnedObject();
> envelop.Content = ptrBytes;
> ============================================================
> // encrypt data
> ADODB.Stream stream = msg.BodyPart.GetEncodedContentStream();
> stream.Type = StreamTypeEnum.adTypeText;
> stream.WriteText(envelop.Encrypt(CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64
> ), StreamWriteEnum.stWriteLine);
> stream.Flush();
> stream.Close();
>
> GCBytes.Free();
>
> // send message
> msg.Send();
> ============================================================================
> ===
> Do let me know how it works for you.
>
> Thanks!
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Community Support
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>