VB.Net Code for signing an email

J

Jeffrey Tan[MSFT]

Hi Jason,

Thanks for your patient.

I have received your demo project. However, I still can not get the
confirmation if there is a build-in support for this in .Net2.0. I am
current contacting other support team regarding your issue. Thanks for your
understanding.

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.
 
J

Jeffrey Tan[MSFT]

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 = "(e-mail address removed)";
msg2.To = "(e-mail address removed)";
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 = "(e-mail address removed)";
msg.To = "(e-mail address removed)";
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.
 
G

Guest

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]" said:
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 = "(e-mail address removed)";
msg2.To = "(e-mail address removed)";
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 = "(e-mail address removed)";
msg.To = "(e-mail address removed)";
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.
 
J

Jeffrey Tan[MSFT]

Hi Jason,

Thanks for your feedback!

Yes, I see your concern. I will still contact the US support team to
discuss this. We will update you as soon as we get any further information,
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.
 
J

Jeffrey Tan[MSFT]

Hi Jason,

Thanks for your patient!

I and the US support team engineer has discussed the possibility of
supportability of S/MIME class in .Net 3.0 (Orcas) with the senior persons
there. No body has a definite answer unless it releases for BETA. Thanks
for your understanding.

You may also feedback this suggestion to the product team in the link below:
http://connect.microsoft.com/Main/content/content.aspx?ContentID=2220

Do let me know if you require any other information on this issue.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top