Contact Us

Scripts: Asp :: mail functions :: Library Article #12

Developer's Section

Send email using ASP.NET
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (3063)

Learn to send email using ASP.NET and the System.Web.Mail namespace.

First make sure to import the System.Web.Mail namespace to your ASP.NET script. Next, we will be creating an object of type MailMessage, then set the required fields on that object and then we use the SmtpMail.Send method to send the object mail to its destination. Below, we show the full ASP.NET code to send an email in HTML format:

 Code Snippet 1

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Math" %>

<script language="vb" runat="server"> 

    Dim recipient As String

    Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
        recipient = ""
        'send email in html format        

        mailMessage = "<html><body>" & vbCrLf
        mailMessage += "<p align=""center""> Hello this is a test email"
        mailMessage += " sent from Erobo Software.</p>" & vbCrLf
        mailMessage += "</body></html>"  & vbCrLf

        Dim myMail As MailMessage = New MailMessage()
        myMail.From = "Erobo Software <>"
        myMail.To = recipient
        myMail.Subject = "Sending email using MailMessage Object"
        myMail.BodyFormat = MailFormat.Html
        myMail.Body = mailMessage
    End Sub


<form  runat=server>
<title>Send Email Using ASP.NET</title>
<p align="center">Congratulations!!<br />
 your message has been send to: <%=recipient%>

See other Scripts in mail functions

Submit Your Scripts:

System Message:
  • Your ASP & ASP.NET script has been sent. Please allow 48 hours for processing.

If you would like to have your ASP & ASP.NET scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]