1 2 //This code shows how tto send email using asp.net in delphi. 3 unit WebForm1; 4 5 interface 6 7 uses 8 System.Collections, System.ComponentModel, 9 System.Data, System.Drawing, System.Web, System.Web.SessionState, 10 System.Web.UI, System.Web.UI.WebControls, System.Web.UI.HtmlControls, 11 System.Web.Mail; 12 13 type 14 TWebForm1 = class(System.Web.UI.Page) 15 {$REGION 'Designer Managed Code'} 16 strict private 17 procedure InitializeComponent; 18 procedure Button1_Click(sender: System.object; e: System.EventArgs); 19 {$ENDREGION} 20 strict private 21 procedure Page_Load(sender: System.object; e: System.EventArgs); 22 strict protected 23 txtEmail: System.Web.UI.WebControls.TextBox; 24 txtSubject: System.Web.UI.WebControls.TextBox; 25 txtMessage: System.Web.UI.WebControls.TextBox; 26 Button1: System.Web.UI.WebControls.Button; 27 procedure OnInit(e: EventArgs); override; 28 private 29 { Private Declarations } 30 public 31 { Public Declarations } 32 end; 33 34 implementation 35 36 {$REGION 'Designer Managed Code'} 37 /// <summary> 38 /// Required method for Designer support -- do not modify 39 /// the contents of this method with the code editor. 40 /// </summary> 41 procedure TWebForm1.InitializeComponent; 42 begin 43 Include(Self.Button1.Click, Self.Button1_Click); 44 Include(Self.Load, Self.Page_Load); 45 end; 46 {$ENDREGION} 47 48 procedure TWebForm1.Page_Load(sender: System.object; e: System.EventArgs); 49 begin 50 // TODO: Put user code to initialize the page here 51 end; 52 53 procedure TWebForm1.OnInit(e: EventArgs); 54 begin 55 // 56 // Required for Designer support 57 // 58 InitializeComponent; 59 inherited OnInit(e); 60 end; 61 62 procedure TWebForm1.Button1_Click(sender: System.object; e: System.EventArgs); 63 var 64 mmEmail : MailMessage; 65 begin 66 mmEmail := MailMessage.Create; 67 mmEmail.From := 'test@test.com'; 68 mmEmail.to := txtEmail.Text; 69 mmEmail.Bcc := 'who@whatever.com'; 70 mmEmail.Subject := txtSubject.Text; 71 mmEmail.BodyFormat := MailFormat.HTML; 72 mmEmail.Body := txtMessage.Text; 73 //Gets or sets the name of the SMTP relay mail server to use to send e-mail 74 //messages. 75 SmtpMail.SmtpServer := 'localhost';//change host to your smtp server. 76 SmtpMail.Send(mmEmail); 77 78 79 end; 80 81 end.