Sending Mail from ASP.NET web page using

This article will demonstrate you how to send email from a ASP.NET web page.
  • 1532

This article will demonstrate you how to send email from a web page. Sending email is very common in Asp.net application. In order to send an email from an Asp.net web page, you have to use the SmtpMail class, found in the System.Net.Mail namespace, which contains a static method Send.

We use the
SmtpMail and MailMessages classes of the namespace for this purpose. The MailMessages class provides properties and methods for constructing an Email message.

Sending Mail from ASP.NET

<%
@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
     Dim message As New System.Net.Mail.MailMessage("mailto:AmitKumar@xyz.com%22,%20%"AmitKumar@xyz.com")
     message.Subject = "Sending Mail with ASP.NET 2.0"
     message.Body = "sending email"
     Dim smtp As New System.Net.Mail.SmtpClient("localhost")
     smtp.Send(message)
  End Sub
</script>
<
html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>ASP.NET Mail</title>
</head>
<
body>
  <form id="form1" runat="server">
   <div>
   </div>
  </form>
</body>
</
html>

The above code sends an email and the email is queues to the disk.
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.