1. Home
  2. Computing & Technology
  3. Delphi Programming

Sending email messages in .Net

By , About.com Guide

Sending an e-mail message (even with attachments) in Delphi for .Net (ASP.NET or WinForms) is very simple. You don't have to learn complicated syntaxes and other commands to achieve the task. The System.Web.Mail namespace provides the classes for sending email in .NET. MailMessage class manages the mail message contents; SmtpMail class sends email to the mail server.

Here's a sample code:

~~~~~~~~~~~~~~~~~~~~~~~~~
uses System.Web.Mail;
...

var
   MailMessage : System.Web.MailMessage;
begin
   mailMessage := MailMessage.create;
   try
     with mailMessage do
     begin
       From := 'delphi.guide@about.com';
       &To := 'someone@somewhere.net';
       Subject := 'This is the subject line';
       Body := 'this is the mail body text;
       BodyFormat := System.Web.Mail.MailFormat.Text;
     end;
     SmtpMail.SmtpServer := 'SMTPSERVER NAME';
     SmtpMail.Send(mailMessage) ;
   except on e : Exception do
     MsgResult.Text := 'Error occured!';
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Delphi for .Net Code Folding keyboard shortcuts
« How to append HTML directly to a WebBrowser document

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2004 Delphi Tips
  7. Sending email messages in .Net

©2009 About.com, a part of The New York Times Company.

All rights reserved.