D
Devhead
i need to present user with an Outlook mail item. the following code is a
modication to the code found
here(http://support.microsoft.com/?kbid=819398). However, when the line is
question is run(Outlook.MailItemClass mItem =
(Outlook.MailItemClass)oDoc.MailEnvelope.Item, it generated an exception
of type System.ExecuteOnEngineException with the following message:
"Object reference not set to an instance of an object"
private static Word._Application oWord = null;
public static void SendEmail(ref Word._Application oWord)
{
object oDocType = Word.WdNewDocumentType.wdNewEmailMessage;
oDoc = oWord.Documents.Add(
ref oMissing,
ref oMissing,
ref oDocType,
ref oFalse);
Outlook.MailItemClass mItem = (Outlook.MailItemClass)oDoc.MailEnvelope.Item;
mItem.To = "(e-mail address removed)";
mItem.BCC = "none";
mItem.CC = "none";
mItem.Subject = "Test message";
mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mItem.HTMLBody = "something going on here";
mItem.ItemEvents_Event_Close += new
Outlook.ItemEvents_CloseEventHandler(oWord_Close);
oWord.Visible = true;
// Loop until there are no more references to release.
while (Marshal.ReleaseComObject(mItem) > 0);
mItem = null;
// Invoke the .NET garbage collector.
GC.Collect();
GC.WaitForPendingFinalizers();
}
// Close the Word application after the message has been sent.
private static void oWord_Close(ref bool e)
{
CloseWordApp(ref oWord);
}
modication to the code found
here(http://support.microsoft.com/?kbid=819398). However, when the line is
question is run(Outlook.MailItemClass mItem =
(Outlook.MailItemClass)oDoc.MailEnvelope.Item, it generated an exception
of type System.ExecuteOnEngineException with the following message:
"Object reference not set to an instance of an object"
private static Word._Application oWord = null;
public static void SendEmail(ref Word._Application oWord)
{
object oDocType = Word.WdNewDocumentType.wdNewEmailMessage;
oDoc = oWord.Documents.Add(
ref oMissing,
ref oMissing,
ref oDocType,
ref oFalse);
Outlook.MailItemClass mItem = (Outlook.MailItemClass)oDoc.MailEnvelope.Item;
mItem.To = "(e-mail address removed)";
mItem.BCC = "none";
mItem.CC = "none";
mItem.Subject = "Test message";
mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mItem.HTMLBody = "something going on here";
mItem.ItemEvents_Event_Close += new
Outlook.ItemEvents_CloseEventHandler(oWord_Close);
oWord.Visible = true;
// Loop until there are no more references to release.
while (Marshal.ReleaseComObject(mItem) > 0);
mItem = null;
// Invoke the .NET garbage collector.
GC.Collect();
GC.WaitForPendingFinalizers();
}
// Close the Word application after the message has been sent.
private static void oWord_Close(ref bool e)
{
CloseWordApp(ref oWord);
}