Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to send a mail with an attachment with outlook from Delphi 7.

Posted on 2004-10-01
6
Medium Priority
?
464 Views
Last Modified: 2010-04-05
Hi. Here is my first question:

I want to send a mail from Delphi7 throught Outlook.
I think is possible with TOutlookApplication object, but i can't find any documentation.
I only need to open a "new mail" outlook form, with an attachment, and some text on Subject.
Can i do that?.


0
Comment
Question by:Colorker
  • 3
  • 3
6 Comments
 
LVL 6

Accepted Solution

by:
vadim_ti earned 500 total points
ID: 12198405
you need to include unit Mapi.


function SendMail(const Subject, Body, FileName,
                  SenderName, SenderEMail,
                  RecipientName, RecipientEMail: string): Integer;
var
  msg: TMapiMessage;
  lpSender, lpRecipient: TMapiRecipDesc;
  FileAttach: TMapiFileDesc;

  SM: TFNMapiSendMail;
  MAPIModule: HModule;
begin
  FillChar(msg, SizeOf(msg), 0);
  with msg do
  begin
    if (Subject <> '') then
      lpszSubject := PChar(Subject);

    if (Body <> '') then
      lpszNoteText := PChar(Body);

    if (SenderEmail <> '') then
    begin
      lpSender.ulRecipClass := MAPI_ORIG;
      if (SenderName = '') then
        lpSender.lpszName := PChar(SenderEMail)
      else
        lpSender.lpszName := PChar(SenderName);
      lpSender.lpszAddress := PChar(SenderEmail);
      lpSender.ulReserved := 0;
      lpSender.ulEIDSize := 0;
      lpSender.lpEntryID := nil;
      lpOriginator := @lpSender;
    end;

    if (RecipientEmail <> '') then
    begin
      lpRecipient.ulRecipClass := MAPI_TO;
      if (RecipientName = '') then
        lpRecipient.lpszName := PChar(RecipientEMail)
      else
        lpRecipient.lpszName := PChar(RecipientName);
      lpRecipient.lpszAddress := PChar(RecipientEmail);
      lpRecipient.ulReserved := 0;
      lpRecipient.ulEIDSize := 0;
      lpRecipient.lpEntryID := nil;
      nRecipCount := 1;
      lpRecips := @lpRecipient;
    end
    else
      lpRecips := nil;

    if (FileName = '') then
    begin
      nFileCount := 0;
      lpFiles := nil;
    end
    else
    begin
      FillChar(FileAttach, SizeOf(FileAttach), 0);
      FileAttach.nPosition := Cardinal($FFFFFFFF);
      FileAttach.lpszPathName := PChar(FileName);

      nFileCount := 1;
      lpFiles := @FileAttach;
    end;
  end;

  MAPIModule := LoadLibrary(PChar(MAPIDLL));
  if MAPIModule = 0 then
    Result := -1
  else
    try
      @SM := GetProcAddress(MAPIModule, 'MAPISendMail');
      if @SM <> nil then
      begin
        Result := SM(0, Application.Handle, msg, MAPI_DIALOG or MAPI_LOGON_UI, 0);
      end
      else
        Result := 1;
    finally
      FreeLibrary(MAPIModule);
    end;
end;

0
 

Author Comment

by:Colorker
ID: 12198527
It works fine!!!.

Only one question:

I leave in blank Sendername, SenderEmail, recipientName and recipientEmail:

sendmail('Report Sales mailing','Your sales report is here.','c:\report001.pdf','','','','');

The recipient must be filled by the user in the Outlook form.
But... what about Sendername and Sendermail? can this fail in some cases?.

Thanks and sorry for my English.

 




0
 
LVL 6

Expert Comment

by:vadim_ti
ID: 12198534
i think it will not fail, but some providers will block such e-mails as spam
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!

 

Author Comment

by:Colorker
ID: 12198560
ups, only one more thing.

If in a future y process a large number of mail's to be send, can i do the process automatically filling all fields , (not outlook form pop-up)?
0
 
LVL 6

Expert Comment

by:vadim_ti
ID: 12198578
I think if you will not set
MAPI_DIALOG
flag, e-mail client interface will not be running, test it
0
 

Author Comment

by:Colorker
ID: 12198662
oK.Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

886 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