?
Solved

Send the body of the message to a application from a client

Posted on 2010-01-13
3
Medium Priority
?
239 Views
Last Modified: 2013-11-05
Hi,

I have a microsoft outlook 2003 client running all the time.

The goal is to get the body text of a mail to a application started from a rule on the client.
in the rules i can start application or run a script
which do i need to use and how i get to the body of the message ?
the body is plain text

the idea is something like parameters in dos batches
start.exe %bodytext%
0
Comment
Question by:Geert Gruwez
[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 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 26305937
Hi, Geert_Gruwez.

While this is possible from Outlook 2003 you are going to encounter a problem.  Outlook 2000 - 2003 includes a security feature that prevents code from accessing any field that contains or may contain an email address without the user's permission.  Accessign the body from code is going to trigger this built-in security feature.  The result is a pop-up dialog-box warning that an application is attemtpting to access your mailbox and askign you for permssion to allow it to continue.  This security feature cannot be turned off, but there are ways to work around it.  Those are

1.  Sign the code.  Here's a link to instructions on doing that: http://msdn.microsoft.com/en-us/library/aa155754(office.10).aspx
2.  Use ClickYes (http://www.contextmagic.com/express-clickyes/), a small utility that'll click the Yes button for you.  It creates a security hole though, since a virus could start sending messages and ClickYes would click the Yes button for it too.  
3.  Use Redemption (http://www.dimastr.com), a COM library that enables code to safely bypass Outlook security.

Security aside, accessing the body is simple.  Something like this will do it.
Sub GetTheBody()
    Dim olkMsg As Outlook.MailItem, strBody As String
    'Get the currently selected message'
    Set olkMsg = Application.ActiveExplorer.Selection(1)
    strBody = olkMsg.Body
    'Your code for launching your program goes here'
    Set olkMsg = Nothing
End Sub

Open in new window

0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 26378196
thx for the code,
as i'm not a VB programmer, but a Delphi programmer i made a other sample

i used your comments as a starting point
thx for the help

there is indeed the warning window which keeps asking about the app trying to read the mails.
this is solved in outlook 2007

function TfrmAlerter.FindFolder(aName: string; aFolder: MapiFolder): MapiFolder;
var
  I: OleVariant;
  n: Integer;
  x: MapiFolder;
begin
  Result := nil;
  if aFolder.Name = aName then
    Result := aFolder
  else
  begin
    n := aFolder.Folders.Count;
    if n > 0 then
    begin
      I := 1;
      while I <= n do
      begin
        x := FindFolder(aName, aFolder.Folders.Item(I));
        if Assigned(x) then
        begin
          Result := X;
          Break;
        end;
        I := I +1;
      end;
    end;
  end;
end;

function TfrmAlerter.ValidMsg(m: MailItem): Boolean;
var
  List: TStringList;
  I, n: integer;
  Msg: string;
begin
  Result := False;
  Msg := UpperCase(m.Body);
  List := TStringList.Create;
  try
    List.StrictDelimiter := True;
    List.CommaText := textFind;
    n := 0;
    for I := 0 to List.Count - 1 do
      if Pos(UpperCase(List[I]), Msg) > 0 then
        Inc(n);
    if n >= List.Count then
      Result := True;
  finally
    List.Free;
  end;
end;

procedure TfrmAlerter.CheckMails;
var f: MapiFolder;
  n: Integer;
  I: OleVariant;
  m: MailItem;
  x: IDispatch;
begin
  outlook.Connect;
  try
    I := 1;
    f := FindFolder(FolderFind, outlook.GetNamespace('MAPI').GetDefaultFolder(olFolderInbox));
    if Assigned(f) then
    begin
      I := 1;
      n := f.Items.Count;
      while I < n do
      begin
        x := f.Items.Item(I);
        if x.QueryInterface(_MailItem, m) = S_OK then
        begin
          if m.UnRead <> False then
          begin
            if ValidMsg(m) then
            begin
              SendSms(m.Subject + ' ' + m.Body);
              m.UnRead := False;
            end;
          end;
        end;
        I := I + 1;
      end;
    end;
  finally
    outlook.Disconnect;
  end;
end;

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
ID: 26380963
That warning is part of Outlook's built in security.  There is no way to turn it off, but there are ways to work around it.  Unfortunately I don't have any experience with Delphi and have no idea if all of these will work with it.  Here are the workarounds.

1.  Sign the code.  Here's a link to instructions on doing that: http://msdn.microsoft.com/en-us/library/aa155754(office.10).aspx
2.  Use ClickYes (http://www.contextmagic.com/express-clickyes/), a small utility that'll click the Yes button for you.  It creates a security hole though, since a virus could start sending messages and ClickYes would click the Yes button for it too.  
3.  Use Redemption (http://www.dimastr.com), a COM library that enables code to safely bypass Outlook security.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

800 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