How to send emails using ASP.Net (VB)?

This topic includes the sample code to send email from ASP.Net(VB) code :

Sample Code :

<%@ Import Namespace="System.Net.Mail" %>
<script runat="server">
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim strFrom = ""
        Dim strTo = ""
        Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo))
        MailMsg.BodyEncoding = Encoding.Default
        MailMsg.Subject = "This is a test email using VB.Net Code"
        MailMsg.Body = "This is a test email using VB.Net Code"
        MailMsg.Priority = MailPriority.High
        MailMsg.IsBodyHtml = True
        Dim SmtpMail As New SmtpClient
        Dim basicAuthenticationInfo As New System.Net.NetworkCredential("", "password")

        SmtpMail.Host = ""
        SmtpMail.UseDefaultCredentials = False
        SmtpMail.Credentials = basicAuthenticationInfo
        lblMessage.Text = "Mail Sent"     
        End Sub
    <form runat="server">
        <asp:Label id="lblMessage" runat="server"></asp:Label>

Note :-  You will require to make some changes in your script like SMTP server, email address & password etc.
  • 630 Users Found This Useful

Was this answer helpful?

Related Articles

How to use ASP Email?

ASPEmail 5.0 is an active server component for sending e-mail messages using an external SMTP...

How to send email through CDONTS Email?

CDONTS stands for "Collaboration Data Objects for Windows NT Server" and as the name suggests it...

How to use ASPSMS?

Here is the ASP VB-Script example, intended to be used on an IIS (Internet Information Server)...

ASPJpeg support on Windows 2008 / 2012 servers

Yes, we have installed ASPJpeg component on Windows 2008 and Windows 2012 shared hosting servers....

How to create ASPNETDB database using aspnet_regsql tool?

What is ASPNETDB? Microsoft has introduced a new and powerful default database schema in...