Save / Import Outlook Messages

Add-in Express™ Support Service
That's what is more important than anything else

Save / Import Outlook Messages
Save / Import Outlook Messages 
H Philip




Posts: 17
Joined: 2005-01-14
Is there a way to save and import outlook messages in .Msg format or other?
Posted 26 Jan, 2005 05:03:04 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Philip,

To save a message see the SaveAs method of the MailItem interface.
For example:
IMail.SaveAs('c:\temp\message.msg', olMSG);

Unfortunately the Outlook Object Model (OOM) doesn't contain any methods for importing messages. Although there is the Move method that moves a message to a certain folder. So you can try to open a stored message and try to move it.

Posted 26 Jan, 2005 05:56:49 Top
H Philip




Posts: 17
Joined: 2005-01-14
So you can try to open a stored message and try to move it


A stored message by means of a messge located in one of the outlook folder or as a .Msg file?
Posted 26 Jan, 2005 09:31:25 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Msg file. Sorry for being not precise enough.

Posted 26 Jan, 2005 09:54:08 Top
Guest


Guest


Thanks for your reply. If so, what is the method I should call to open a .Msg file?
Posted 26 Jan, 2005 10:11:59 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Since Outlook Object Model doesn't contain such a method you can call ShellExecute or something like that.

Posted 26 Jan, 2005 10:32:06 Top
H Philip




Posts: 17
Joined: 2005-01-14
ShellExecute won't help because it open the message. Maybe I need a different approach, is there a way to retreive all the items of a specific folder without selecting it for example the Draft folder ?
Posted 26 Jan, 2005 11:32:51 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Philip,

See the sample code below.


var
  i: Integer;
  IDsp: IDispatch;
  IMail: MailItem;
  IFolder: MAPIFolder;
begin
  IFolder := OutlookApp.GetNamespace('MAPI').GetDefaultFolder(olFolderDrafts);
  try
    for i := 1 to IFolder.Items.Count do begin
      IDsp := IFolder.Items.Item(i);
      IDsp.QueryInterface(IID__MailItem, IMail);
      if Assigned(IMail) then begin
        //
        //
        //
      end;
    end;
  finally
    IMail := nil;
    IDsp := nil;
    IFolder := nil;
  end;
end;

Posted 27 Jan, 2005 07:36:46 Top
Johnny Bravenboer




Posts: 13
Joined: 2006-03-20
Hi,

I was trying to make use of the coding provided in this thread, but I must be missing something here, because when I try to compile, the compiler tells me:

Undeclared identifier: 'MailItem'
Undeclared identifier: 'MAPIFolder'

Do I need to add something to my uses list before using this coding?

Thanks and regards,

John... ;)
Posted 20 Mar, 2006 23:43:20 Top
Nicholas Glasier


Guest


Try adding Outlook2000 to your uses clause.

If Delphi can't find it when you compile, the file should be in your Delphi xx \OCX\Servers folder where xx is the version of Delphi you are using. You will need to add a path to this folder to Delphi's search path (Delphi Tools menu, Environment Options, Libray). You will see a lot of other .pas files in that folder which are used to provide interfaces with other MSOffice applications.


Regards Nick
Posted 21 Mar, 2006 00:07:55 Top