Solved

Save Active Mail Item in Outlook to Hard Disk (.MSG)

Posted on 2009-04-05
3
729 Views
Last Modified: 2013-11-23
Hi there,

I am using a add-in-express that allows me to build add-ins for MS outlook.  It makes inserting buttons etc really easy in Outlook, but I still need to write the applied code.  I need some assistance to save the currently active mail item to my hard disk when a user clicks a my add-in button inside outlook.

Thanks,

Phillip
0
Comment
Question by:meneerroux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 24077316
Here is an example of outlook automation that I posted some time back. Take a look and see if that gives you the start you need.
http://www.experts-exchange.com/Microsoft/Development/Microsoft_Programming/Q_23216275.html
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 500 total points
ID: 24081243
Here's some code we use on our addin. We use Add-in Express, too, and it is a wonder to work with that tool
as it does tons of work for you.

uses  ..., Outlook2000;
 
 
var
  strTempFilePath: String;
  bSaved: Boolean;
  IMail: _MailItem;
  IExpl: _Explorer;
  ISel: Selection;
begin
  IExpl := FAddin.OutlookApp.ActiveExplorer();
  if Assigned(IExpl) then
  begin
    try
      try
        ISel := IExpl.Selection;
      except
        ISel := nil;
      end;
      if Assigned(ISel) then
      try
        if ISel.Count > 0 then
        begin
          ISel.Item(1).QueryInterface(IID__MailItem, IMail);
          if Assigned(IMail) then
          begin
            try
              strTempFilePath := IMail.Subject + '.msg';
              if FileExists(strTempFilePath) then
                SysUtils.DeleteFile(strTempFilePath);
              strDocDescription := IMail.Subject;
              IMail.SaveAs(strTempFileName, olMSG);
              bSaved := True;
              if not IMail.Sent then
              begin
                IMail.Send;
              end;
            finally
              IMail := nil;
            end;
          end;
        end;
      finally
        ISel := nil;
      end;
    finally
      IExpl := nil;
    end;
  end;
end;  

Open in new window

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24081246
BTW, that code sends the email if it hasn't been sent, too. I forgot to take that out.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question