Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2010-01-13
3
Medium Priority
?
250 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
  • 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
As a matter of fact, Outlook OST files are of much importance in relation to Exchange mailbox. OST files are independent as they are simply copy of data of a user’s mailbox on Exchange Server. Though, if the server’s status is changed or it is dama…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

581 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