• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1279
  • Last Modified:

Outlook mail window.

Hi,
I'm creating an excel file using delphi, then generate a mail in outlook using delphi by the code;

          OutLookObject := CreateOleObject('Outlook.Application');
          MailObject := OutLookObject.CreateItem(0);
          MailObject.Recipients.Add('Me@here.com');
          MailObject.Subject := 'Hi';
          MailObject.Attachments.add('Something.xls');
          MailObject.Send;

where I add the attachment. This works like a charm, but now I would like to display the mail like you normally would in Outlook instead of sending it, so the user may edit the attachment or body before manually sending it. I've tried to find a .visible or .display command, but I can't seem to get this to work. Any ideas?

0
Aqueath
Asked:
Aqueath
1 Solution
 
IEliteCommented:
function TForm1.SendEmail(Address, Subject: String; Body: AnsiString; Filename: string=''): Boolean;
var
  Outlook : Variant;
  Item    : Variant;
begin
  try
    CoInitializeEx(nil, 0);
    Outlook:=CreateOLEObject('Outlook.Application');
    try
      Item:=outlook.CreateItem(0);
      Item.Subject:=Subject;
      Item.Body:=Body;
      if FileName<>'' then
        Item.Attachments.Add(FileName,1,1,FileName);
      Item.To:=Address;
      Item.Send;
    finally
    end;
  except
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 SendEmail('someone@somewhere.com', 'Test', 'Hello', '');
end;

ShaneHolmes
0
 
AqueathAuthor Commented:
Thanks for the swift reply Shane, but I believe you are doing exactly what I'm allready doing, only you've made a function of it. The thing is;

-Outlook creates a mail instance right? This instance contains subject, body, attachment, etc
-We both create the mail, AND send it.

What I would like to do is create the mail with attachment and all, then VIEW it on screen like any other mail draft from outlook.

So that means

-Create mail
-Put in subject, recipient, attachment etc
-View mail
-Let user change whatever is needed, then send it manually by clicking the send button in outlook.


Hope that makes sense.


A.
0
 
AqueathAuthor Commented:
Or put in terms of the code I posted initally;

          OutLookObject := CreateOleObject('Outlook.Application');
          MailObject := OutLookObject.CreateItem(0);
          MailObject.Recipients.Add('Me@here.com');
          MailObject.Subject := 'Hi';
          MailObject.Attachments.add('Something.xls');
          MailObject.<Visible/View/Display/Something>

A.
0
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.

 
AqueathAuthor Commented:
Argh. It appears I solved it myself without knowing...


          OutLookObject := CreateOleObject('Outlook.Application');
          MailObject := OutLookObject.CreateItem(0);
          MailObject.Recipients.Add('Me@here.com');
          MailObject.Subject := 'Hi';
          MailObject.Attachments.add('Something.xls');
          MailObject.Display;

Thanks for your comment Shane. Sorry to have wasted your time.

A.

PAQ please?
0
 
shaneholmesCommented:
No problem, just request to delete - I wont object!
0
 
GhostModCommented:
PAQd, 500 points refunded.

GhostMod
Community Support Moderator
0
 
GDQ-JWCommented:
I suggest you encapsulate the Display function in a try-except block, otherwise it may throw responses that Delphi interprets as an error:

try
  MailObject.Display;
except
end;
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now