?
Solved

Send message to another Exchange mailbox

Posted on 2001-06-14
7
Medium Priority
?
249 Views
Last Modified: 2010-05-18
Hello,

Can anyone tell me if there's a easy way in Delphi to send a message to an Exchange Server mailbox of another user.
I just want to specify the parameters: mailbox (or e-mail address), subject an message text.

Thanks,
JDN
0
Comment
Question by:JDN
[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
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:MaxSCZ
ID: 6190886
Hi,
this can help?



procedure TForm1.mnuEmailClick(Sender: TObject);
var
  cCommand: String ;
  cBody: String ;
begin
  cBody := 'Dir sir(s)%0d%0aI would like to inform you that%0d%0athe
following' ;
  cCommand := 'mailto:PersonToSendTo.com'   +
              '?Subject=Subject goes here'  +
              '&cc=AddressToCC.com'         +
              '&bcc=BlindCC.com'            +
              '&body=' + cBody ;

  if ShellExecute(0, nil, PChar(cCommand), nil, nil, SW_SHOWDEFAULT) <= 32
then
  begin
    MessageDlg('Your error message on failure',mtError,[mbOk],0) ;
  end else begin
    { The following attempts to send the email by invoking send via the menu
}
    Sleep(1000);                                  {give mail prog time to
open}
    keybd_Event(VK_MENU, 0, 0, 0);                {get email prog menu}
    keybd_Event(ord('S'), 0, 0, 0);               {s for send}
    keybd_Event(ord('S'), 0, KEYEVENTF_KEYUP, 0); {click}
    keybd_Event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);  {exit menu}
    ShowMessage('Finished!') ;
  end ;
end;


bye Max
0
 
LVL 1

Accepted Solution

by:
Phoenix_s earned 150 total points
ID: 6193259
this works too, although it does require outlook to be installed on the PC.




wherever you put this has to have   comobj   in the USES clause!
----------------------------------------------------------------
procedure email(sendto, subject: string; body: tstrings);
const
  // for email capability
  olFolderDeletedItems = $00000003;
  olFolderOutbox = $00000004;
  olFolderSentMail = $00000005;
  olFolderInbox = $00000006;
  olFolderCalendar = $00000009;
  olFolderContacts = $0000000A;
  olFolderJournal = $0000000B;
  olFolderNotes = $0000000C;
  olFolderTasks = $0000000D;
  olMailItem = 0;

var str1, str2, str3 : string;
    pos1 : integer;
var
  outlook, nmspace, mailitem: olevariant;

begin
 
  try
    outlook := getactiveoleobject('outlook.application');
  except
    outlook := createoleobject('outlook.application');
  end
 
  nmspace := outlook.getnamespace('MAPI');
  nmspace.logon(emptyparam, emptyparam, false, true);
  mailitem := outlook.createitem(olmailitem);
  pos1 := pos(';',sendto);
  if pos1 = 0 then
    mailitem.recipients.add(sendto)
  else
    begin
      str3 := sendto;
      repeat
        str1 := copy(str3,1,pos1-1);
        str2 := copy(str3,pos1+1,(length(str3)-length(str1)));
        mailitem.recipients.add(str1);
        str3 := str2;
        pos1 := pos(';',str3);
      until pos1 = 0;
      mailitem.recipients.add(str3);
    end;
  mailitem.subject := subject;
  mailitem.body := body.text;
  mailitem.send;
  nmspace.logoff;
  nmspace := unassigned;
  mailitem := unassigned;
  outlook := unassigned;
end;

--------------------------------------------------------------------

to use, just call email(sendto,subject,body)

* sender can be multiple recipients seperated by ';'  the procedure will parse the individual recipients out appropriately and add them to the TO: field in the message.

0
 
LVL 1

Author Comment

by:JDN
ID: 6196548
Phoenix,

When I call procedure email, with the three parameters, I get an error:

Access violation at address 77E1513A in module 'user32.dll'.

I'm using Outlook 2000. The error comes up with Outlook running and with Outlook not running.

Any idea?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Phoenix_s
ID: 6196922
JDN: really... cuz that worked with win98 SE, win95, and win2k  with outlook 97,98,and 2k in various permutations

try this-  I just ran it and it works


unit source:
------------------------------------------------------------------------------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,comobj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

procedure email(sendto,subject:string;body:tstrings);

var
  Form1: TForm1;

implementation


procedure email(sendto, subject: string; body: tstrings);
const
 // for email capability
 olFolderDeletedItems = $00000003;
 olFolderOutbox = $00000004;
 olFolderSentMail = $00000005;
 olFolderInbox = $00000006;
 olFolderCalendar = $00000009;
 olFolderContacts = $0000000A;
 olFolderJournal = $0000000B;
 olFolderNotes = $0000000C;
 olFolderTasks = $0000000D;
 olMailItem = 0;

var str1, str2, str3 : string;
   pos1 : integer;
var
 outlook, nmspace, mailitem: olevariant;

begin
 
 try
   outlook := getactiveoleobject('outlook.application');
 except
   outlook := createoleobject('outlook.application');
 end ;
 
 nmspace := outlook.getnamespace('MAPI');
 nmspace.logon(emptyparam, emptyparam, false, true);
 mailitem := outlook.createitem(olmailitem);
 pos1 := pos(';',sendto);
 if pos1 = 0 then
   mailitem.recipients.add(sendto)
 else
   begin
     str3 := sendto;
     repeat
       str1 := copy(str3,1,pos1-1);
       str2 := copy(str3,pos1+1,(length(str3)-length(str1)));
       mailitem.recipients.add(str1);
       str3 := str2;
       pos1 := pos(';',str3);
     until pos1 = 0;
     mailitem.recipients.add(str3);
   end;
 mailitem.subject := subject;
 mailitem.body := body.text;
 mailitem.send;
 nmspace.logoff;
 nmspace := unassigned;
 mailitem := unassigned;
 outlook := unassigned;
end;



{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var emailbody : tstrings;
begin
  emailbody := tstringlist.create;
  emailbody.add('This is a dumb test');
  emailbody.add('this is the second line of the dumb test');


  email('jhack@okspring.com','test email',emailbody);
  emailbody.free;
end;

end.
----------------------------------------------------------

form:
-----------------------------------------------------------------------------------
object Form1: TForm1
  Left = 192
  Top = 123
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 48
    Top = 60
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
end

------------------------------------------------------------------------

Project:

------------------------------------------------------------------------
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
----------------------------------------------------------------------------



0
 
LVL 1

Expert Comment

by:Phoenix_s
ID: 6196927
OH... and, this is done in delphi 5, but it has worked with delphi4 as well with no changes to the code.

dunno about delphi 3 though, haven't run it in a couple years... ehhehe
0
 
LVL 1

Expert Comment

by:Phoenix_s
ID: 6196944
MaxSCZ's proc works too except you gotta have shellAPI in the uses clause...
0
 
LVL 1

Author Comment

by:JDN
ID: 6201159
Phoenix,

Now your procedure works.
Perhaps I did something wrong.

MaxSCZ's solution works, but I prefer the OLE call to Outlook. So, I give Phoenix the points.

Thank you both.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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