Problem with Setting: "urn:schemas:mailheader:content-disposition"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am attempting to send a message using CDO in a ASP.NET/C# Application:

I receive the following Error when trying to update the fields:

////////////////////////////////////////////

ERROR

////////////////////////////////////////////

Fields update failed. For further information, examine the Status property
of individual field objects.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Fields
update failed. For further information, examine the Status property of
individual field objects.

////////////////////////////////////////////

The code looks like the following:

////////////////////////////////////////////


//// CLASS VARIABLES
static private String _currStoreName = "My";
static StoreClass _oCurrStore;

const string CDO_MailServer = "mail.dovetailinternet.com";
const string CDO_ContentDisposition = "attachment;filename=smime.p7m";
const int CDO_SmtpPort = 25;
const int CDO_SendUsingType = 2;

private Certificates oCerts;
private Certificate oCert;

private EnvelopedData oEnvData;


////METHODS

private void CDOMail()
{
CDO.Configuration mailerConfig = new CDO.ConfigurationClass();
CDO.IMessage firstMsg = new CDO.MessageClass();
CDO.IMessage secondMsg = new CDO.MessageClass();

mailerConfig.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO_SendUsingType
mailerConfig.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = CDO_MailServer;
mailerConfig.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = CDO_SmtpPort;
mailerConfig.Fields.Update();

firstMsg.Sender = "(e-mail address removed)";
firstMsg.To = "(e-mail address removed)";
firstMsg.Subject = "First Message Subject";
firstMsg.TextBody = "Message One Body";

secondMsg.DataSource.OpenObject(firstMsg, "IMessage");

CDO.IBodyPart oBodyPart = secondMsg.BodyPart;
oBodyPart.ContentMediaType =
"application/pkcs7-mime;smime-type=enveloped-data;name=smime.p7m;";
oBodyPart.ContentTransferEncoding = "base64";

//*** Update That Fails
oBodyPart.Fields["urn:schemas:mailheader:content-disposition"].Value =
CDO_ContentDisposition;
oBodyPart.Fields.Update();
//***

secondMsg = EnvelopeMessage(secondMsg);
secondMsg.Configuration = mailerConfig;
secondMsg.Send();
}

private CDO.IMessage EnvelopeMessage(CDO.IMessage msg)
{
CDO.Message oSecMsg = new CDO.MessageClass();

oSecMsg.DataSource.OpenObject(msg, "IMessage");

_oCurrStore = new StoreClass();
_oCurrStore.Open(CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE,
_currStoreName,CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_EXISTING_ONLY |
CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);

oCerts = (Certificates)_oCurrStore.Certificates;

foreach(Certificate cert in oCerts)
{
oCert = cert;
}

CAPICOM.EnvelopedData oEnvData = new CAPICOM.EnvelopedDataClass();
oEnvData.Recipients.Add(oCert);

ADODB.Stream tmpStream = oSecMsg.BodyPart.GetStream();
string strContent = tmpStream.ReadText(tmpStream.Size);
oEnvData.Content = strContent;

string strData =
oEnvData.Encrypt(CAPICOM.CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64);

ADODB.Stream oStream = oSecMsg.BodyPart.GetDecodedContentStream();
oStream.Type = ADODB.StreamTypeEnum.adTypeBinary;

byte[] byteData = Convert.FromBase64String(strData);

oStream.Write(byteData);
oStream.Flush();
oStream.Close();

return oSecMsg;
}



Any help would be greatly appreciated, i've been trying to resolve the issue
for hours on end, and know that eliminating this error will likely yield the
desired effect.

I have been unable to find any good examples of sending CDO.Mail with .NET
except the one here:

http://support.microsoft.com/Default.aspx?kbid=280391

I Followed the Instructions and am now faced with this problem. Please Help
me!
 
Back
Top