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
Solved

Send a mail

Posted on 2000-02-15
4
236 Views
Last Modified: 2008-02-01
Hello,
I want send a mail in my application.
Is someone know how?
                                        thanks
                                                      Gaëlle
0
Comment
Question by:gaelle
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 2526012
You can start an email like this:

shellexecute(Handle, 'open', 'mailto:Fred@fred.com?Hi There!', nil, nil, sw_show);

Though the user then has to fill in the message and send it.

Or you can use something like this which uses mapi to set up a mail message including attachments and send it:

uses mapi;

function SendEMail(Handle :THandle;Mail :TStrings) :Cardinal;
 type
   TAttachAccessArray    = array [0..0] of TMapiFileDesc;
   PAttachAccessArray    = ^TAttachAccessArray;
 var
   MapiMessage : TMapiMessage;
   Receip      : TMapiRecipDesc;
   Attachments : PAttachAccessArray;
   AttachCount : Integer;
   i1          : integer;
   FileName    : String;

 begin
   fillChar(MapiMessage,SizeOf(MapiMessage),#0);
   Attachments:=nil;
   fillChar(Receip,SizeOf(Receip),#0);
   if Mail.Values['to']<>'' then
   begin
     Receip.ulReserved:=0;
     Receip.ulRecipClass:=MAPI_TO;
     Receip.lpszName:=StrNew(PChar(Mail.Values['to']));
     Receip.lpszAddress:=StrNew(PChar('SMTP:' + Mail.Values['to']));
     Receip.ulEIDSize:=0;
     MapiMessage.nRecipCount := 1;
     MapiMessage.lpRecips    := @Receip;
   end;
   AttachCount:=0;
   for i1:=0 to MaxInt do
   begin
     if Mail.Values['attachment'+inttostr(i1)]='' then break;
     inc(AttachCount);
   end;
   if AttachCount>0 then
   begin
     GetMem(Attachments,SizeOf(TMapiFileDesc)*AttachCount);
     for i1:=0 to AttachCount-1 do
     begin
       FileName:=Mail.Values['attachment'+inttostr(i1)];
       Attachments[i1].ulReserved    := 0;
       Attachments[i1].flFlags       := 0;
       Attachments[i1].nPosition     := ULONG($FFFFFFFF);
       Attachments[i1].lpszPathName  := StrNew(PChar(FileName));
       Attachments[i1].lpszFileName  := StrNew(PChar(ExtractFileName(FileName
 )));
       Attachments[i1].lpFileType    := nil;
     end;
     MapiMessage.nFileCount:=AttachCount;
     MapiMessage.lpFiles:=@Attachments^;
   end;

   if Mail.Values['subject']<>'' then MapiMessage.lpszSubject
 :=StrNew(PChar(Mail.Values['subject']));
   if Mail.Values['body']<>''    then MapiMessage.lpszNoteText
 :=StrNew(PChar(Mail.Values['body']));

   Result :=MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle<>0)
 or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);

   for i1:=0 to AttachCount-1 do
   begin
     strDispose(Attachments[i1].lpszPathName);
     strDispose(Attachments[i1].lpszFileName);
   end;

   if assigned(MapiMessage.lpszSubject)  then
 strDispose(MapiMessage.lpszSubject);
   if assigned(MapiMessage.lpszNoteText) then
 strDispose(MapiMessage.lpszNoteText);
   if assigned(Receip.lpszAddress)       then
 strDispose(Receip.lpszAddress);
   if assigned(Receip.lpszName)          then
 strDispose(Receip.lpszName);
 end;

procedure TForm1.Button1Click(Sender: TObject);
var
mail : tstringlist
begin
mail:=tstringlist.create;
mail.values['to']:='xyz@zz.com';
mail.values['subject']:='no subject';
mail.values['body']:='no subject';
mail.values['body']:='no subject';
mail.values['attachment0']:='c:\winnt\winnt256.bmp';
mail.values['attachment1']:='c:\winnt\winnt.bmp';
sendEMail(application.handle,mail);
mail.free;
end;

Or you can use something like the SakEmail component and send a mail like this:

procedure TSVOExceptForm.Button1Click(Sender: TObject);

begin
  SakSMTP1.host := 'smtp.trimble.co.nz';
   SakMsg1.CharSet := 'ISO-8859-1';  
   SakMsg1.TextEncoding := te8Bit;
       
SakMsg1.UserName := 'Fred';
   SakMsg1.From := '<Fred@fred.com'+'>';
   SakMsg1.SendTo := 'mary@fred.com';
   SakMsg1.Subject := 'Subject line';
   SakMsg1.Text.Assign(Memo2.Lines);
   SakMsg1.Text.append(' ');
   SakMsg1.Text.AddStrings(Memo1.lines);
   SakSMTP1.connect;
   if not SakSMTP1.SMTPError then
   begin
      SakSMTP1.SendTheMessage( SakMsg1);
      SakSMTP1.quit;
      ShowMessage('Message sent to '+ SakMsg1.SendTo);
   end;
end;

Cheers,

Raymond.
0
 

Author Comment

by:gaelle
ID: 2526101
Thanks for your answer Raymond but I don't find
SakEmail component. Where is it ?
                                                         Gaëlle.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2526119
You can also use the TNMSMTP component which ships with delphi, for which I do not have a code sample.

SakEmail can be downloaded from here: http://info.perio.unlp.edu.ar/~sergio/html/sakemail.html

Cheers,

Raymond.
0
 

Author Comment

by:gaelle
ID: 2526197
Thanks a lot Raymond
                                   Gaëlle
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 94
find a node in VST 2 70
Delphi Yen format 3 45
Base1 Encode/Decode 3 81
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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