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

