Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


How do I send an email using Delphi? by Stretchwickster
Posted: 19 May 03 (Edited 5 Oct 05)

This question has been asked frequently in the last few months so I thought it might be useful to collate the information in one central place.

There are two techniques that I know of, by which you can facilitate the sending of email from a Delphi application:
1) by using the simple "mailto" protocol
2) by using the MAPI

This is the simplest technique for sending an email message. It makes use of the default mail application on your computer. A disadvantage is that attachments are not always supported by the default mail application and errors and truncation occur when using Win 9x. ShellAPI will need to be added to the uses clause of the application. Here is the syntax (N.B. I have divided up the string into sections to aid readability):


             'mailto:' +
             'me@me.com' +
             '?Subject=Test Message Subject' +
             '&Body=Test Message Body' +
             '&Attach="c:\Mail Attachments\attachment.txt"',
This code has the effect of opening your default mail application, populating the "To:", "Subject:" and body sections of a new mail message with the values specified in the mailto protocol, ready for you to send. The attach line will have the effect of attaching a file at the specified location (this final line may not work on all mail programs but does function correctly on Outlook)


Messaging Application Programming Interface (MAPI)
This is definitely my preferred method as it doesn't rely on the use of a default mail application and is far more reliable across a range of windows platforms. I won't specify the code here but have provided links in the References section that follows, in which there are two excellent examples of its' use.

http://techtricks.com/delphi/sendmail.php (a contribution from our very own Lance Leonard aka footpad)

Other things to look into using the Delphi help:
- TSendMail
- Indy Components: TIdMessage & TIdSMTP (see   http://www.marcocantu.com/code/md6htm/SendList.htm for an example)

Please feel free to send me corrections/suggestions/comments concerning this FAQ.

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close