Products
Services
Contact Us

Scripts: asp :: ASP.NET 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: (1678)
Favorites:

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 = "customer@erobo.net"
           
        '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 <services@erobo.net>"
        myMail.To = recipient
        myMail.Subject = "Sending email using MailMessage Object"
        myMail.BodyFormat = MailFormat.Html
        myMail.Body = mailMessage
        SmtpMail.Send(myMail)
        
        
    End Sub

</script>

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


See other Scripts in ASP.NET Mail Functions

Submit Your Scripts:

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:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]