Attempting to create (and send) an Outlook MSG file that says sent

P

PromisedOyster

We have an application that automatically sends and saves Outlook
messages. However, what I want to do is somehow get the MSG file to be
marked as 'sent' rather than 'not sent'.

Outlook.Application outlook = null;
Outlook.MailItem mailItem = null;

try
{
object o = Marshal.GetActiveObject("Outlook.Application");
outlook = o as Outlook.Application;
}
catch
{
// unable to connect to open version of Outlook. Create new instance
outlook = new Outlook.ApplicationClass();
}

Object omailItem = outlook.CreateItem(Outlook.OlItemType.olMailItem);
mailItem = omailItem as Outlook.MailItem;
mailItem.To = "(e-mail address removed)";
mailItem.Subject = "Test email";

// The following two lines of code generates the exception:
//An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in TestEmail.exe
// Additional information: The item has been moved or deleted.

// mailItem.Send();
//mailItem.SaveAs("C:\\temp\\TestEmail.MSG",
Outlook.OlSaveAsType.olMSG);

// The following two lines of code saves and sends the email, but the
MSG file says not semt
mailItem.SaveAs("C:\\temp\\TestEmail.MSG", Outlook.OlSaveAsType.olMSG);
mailItem.Send();

What is the simplest way of getting the sent MSG (to save to file) so
it is clear that the MSG has actually been sent?


Your assistance would be greatly appreciated.
 
D

Dmitry Streblechenko

Create the message as a post item (olPostItem) rather than olMailItem - it
will be created in the sent state, then change the MessageClass property to
"IPM.Note". You will need to change the icon as well, but you will need
Extended MAPI/CDO 1.21/Redemption for that: see
http://www.dimastr.com/redemption/faq.htm#8

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
P

PromisedOyster

Thanks Dmitry for the less than obvious solution,

I was contemplating sending the message, then getting the message from
the Sent Items folder. However, this seemed a bit klunky and error
prone. I will try out your suggestion.

Thanks
 
R

Robert Morley

To my knowledge, your suggestion is the only way to do it without relying on
something like Redemption...it's a very annoying problem with Outlook.



Rob
 

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