Mega Code Archive

 
Categories / Delphi / Examples
 

Sending email messages in net

Delphi 8 for .NET makes it easier to send emails even with attachments. The System.Web.Mail namespace provides the necessary classes for sending email in .NET; follow this example. uses System.Web.Mail; procedure SendAnEmail; var MailMessage: System.Web.MailMessage; begin MailMessage := MailMessage.Create; try with MailMessage do begin From := 'me@hotmail.com'; &To := 'you@yahoo.com'; Subject := 'Important news'; Body := 'email body text here'; BodyFormat := System.Web.Mail.MailFormat.Text; end; { with MailMessage } SmtpMail.SMTPSERVER := 'SMTPSERVER name'; SmtpMail.Send(MailMessage) except on e : Exception do MsgResult.Text := 'Error occured!'; end; { try } end;