| 1. |
How Do I Send An Email Message From My Asp.net Page? |
|
Answer» You can use the System.Web.Mail.MailMessage and the System.Web.Mail.SmtpMail class to send email in your ASPX pages. Below is a simple example of using this class to send mail in C# and VB.NET. In order to send mail through our mail server, you would want to make sure to set the static SmtpServer property of the SmtpMail class to mail-fwd. C# <%@ Import Namespace="System" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Web.Mail" %> <HTML> <HEAD> <title>Mail Test</title> </HEAD> <script language="C#" runat="server"> private void Page_Load(Object sender, EventArgs e) { TRY { MailMessage mailObj = new MailMessage(); mailObj.From = "sales@joeswidgets.com"; mailObj.To = "ringleader@forexample-domain.com"; mailObj.Subject = "Your Widget Order"; mailObj.Body = "Your order was processed."; mailObj.BodyFormat = MailFormat.Text; SmtpMail.SmtpServer = "mail-fwd"; SmtpMail.Send(mailObj); Response.Write("Mail sent successfully"); } CATCH (EXCEPTION x) { Response.Write("Your message was not sent: " + x.Message); } } </script> <body> <FORM id="mail_test" method="post" runat="server"> </form> </body> </HTML>You can use the System.Web.Mail.MailMessage and the System.Web.Mail.SmtpMail class to send email in your ASPX pages. Below is a simple example of using this class to send mail in C# and VB.NET. In order to send mail through our mail server, you would want to make sure to set the static SmtpServer property of the SmtpMail class to mail-fwd. |
|