How to send email in ASP.NET 1.1

The following code is applicable to ASP.NET 1.1.  If your site is configured to ASP.NET 2.0, please use the new System.Net.Mail class. See this Knowledge Base article  

<%@ Page Language="VB" %>
<script runat="server">
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
            mailMessage.From = "you@YourHostedDomainName.com"
            mailMessage.To = "someone@somewhere.com"
            mailMessage.Subject = "This is a sample mail sent from ASP.net Mail Component"
            mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
            mailMessage.body = "Congratulation" & VbCrLf & "If you receive this is, your mail component works"
            System.Web.Mail.SmtpMail.SmtpServer = "localhost"
            System.Web.Mail.SmtpMail.Send(mailMessage)
            lblMessage.text = "Mail Sent"
    End Sub
</script>
<html>
<body>
    <form runat="server">
        <asp:Label id="lblMessage" runat="server"></asp:Label>
    </form>
</body>
</html>


If you run into problems when using this code, please post in our community forum. Technical support is unable to assist with specific coding issues.

Article ID: 363, Created On: 11/24/2008, Modified: 4/13/2010