Scalabium Software

SMReport Autogenerated
Knowledge for your independence'.
Home Delphi and C++Builder tips


#49: How can I create the email message?

If you need create the message in your mailing app from your Delphi code, you can:

1. create a message via default mailer using shell api:

uses ShellAPI;
var
  pCh: PChar;
begin
  pCh := 'mailto:mshkolnik@scalabium.com?subject=your_subject&body=your_body';
  ShellExecute(0, 'open', pCh, nil, nil, SW_SHOWNORMAL);
end;

Few additional comments:
1. the some mailers supports the extended syntax with some usefule features. For example, the MS Outlook supports the file attachment via ShellExecute:

var
  pCh: PChar;
begin
  pCh := 'mailto:mshkolnik@scalabium.com?subject=your_subject&body=your_body&file="c:\autoexec.bat"';
  ShellExecute(0, 'open', pCh, nil, nil, SW_SHOWNORMAL);
end;

But other mailers don't supports this file attachment.

2. you must convert a texts which you want to place into subject or body - to change a spaces into "%20"

3. on some builds of MS Windows the all characters from subject and body will be trancated to small length or converted to lower case

2. create a message in Outlook using OLE:

const
  olMailItem = 0;
var
  Outlook, MailItem: OLEVariant;
begin
  try
    Outlook := GetActiveOleObject('Outlook.Application');
  except
    Outlook := CreateOleObject('Outlook.Application');
  end;

  MailItem := Outlook.CreateItem(olMailItem);
  MailItem.Recipients.Add('mshkolnik@scalabium.com');
  MailItem.Subject := 'your subject';
  MailItem.Body := 'Welcome to my homepage: http://www.scalabium.com';
  MailItem.Attachments.Add('C:\Windows\Win.ini');
  MailItem.Send;
  
  Outlook := Unassigned;
end;

If you want to create a message in html-format, you can use the HTMLBody property instead a Body. But note that this HTMLBody property is available staring from Outlook 98 only.


Published: December 6, 1999

See also
 
Clarion to Text converter/a>
Paradox Viewer
SMExport suite
SMMsg suite
SMReport
Mail parser (ActiveX)
Paradox to MS Access converter
ABA Picture Convert
SMDBGrid
Excel Web-stream
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2017, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising