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 = "yourname@yourdomain.com"
        Dim strTo = "recipient_email@domain.com"
        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("smtp@yourdomain.com", "password")

        SmtpMail.Host = "smtp.yourdomain.com"
        SmtpMail.UseDefaultCredentials = False
        SmtpMail.Credentials = basicAuthenticationInfo
 
        SmtpMail.Send(MailMsg)
        lblMessage.Text = "Mail Sent"     
        End Sub
</script>
<html>
<body>
    <form runat="server">
        <asp:Label id="lblMessage" runat="server"></asp:Label>
    </form>
</body>


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

Was this answer helpful?

Related Articles

How to disable Deprecated Function Notices in PHP.

PHP has deprecated some functions in latest version. If the same functions are still on your...

ASPJpeg support on Windows 2008 / 2012 servers

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

Microsoft Access and ASP connection script for Windwos 2008 / 2012 shared hosting

If your website is hosted on our Windows 2008 or Windows 2012 shared hosting server, you will...

Sample script for CDO email

CDO (Collaboration Data Objects) is an inbuilt ASP component used to send emails via ASP. It is...

How to use ASP Simple Upload component?

Sample code: <% Option Explicit Dim upl, NewFileName Set upl =...