Support - Knowledge base

Giving you the answers you need

Why not try our knowledge base for instant help and advice to enhance your online experience with Register365? From within the knowledge base you can browse our frequently asked questions and find the right answers to help solve your queries.

Home  >  Scripting  >  ASP (Active Server Pages)  >  View Article

Example working vb.NET mail script

2*2*2*2*2*

Article

<%@ Page Language="vb" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Web.Mail" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <script runat="server">
            Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
                Dim strMessage As New StringBuilder
                Dim msg1 As New MailMessage
                strMessage.Append("<table border=""0"" cellpadding=""4"" >")
                strMessage.Append("<tr>")
                strMessage.Append("<td>")
                strMessage.Append(tbBody.Text)
                strMessage.Append("</strong>")
                strMessage.Append("</td>")
                strMessage.Append("</tr>")
                strMessage.Append("</table>")
                '***** CHANGE THE NEXT FOUR LINES AS PER REQUIREMENTS *****
                msg1.From = "website@example.com"
                msg1.To = "support@names.co.uk"
                msg1.Cc = "support@names.co.uk"
                msg1.Bcc = "support@names.co.uk"
                '***** NO MORE EDITING REQUIRED AFTER HERE ****************
                msg1.Subject = tbSubject.Text
                msg1.Body = strMessage.ToString
                msg1.BodyFormat = MailFormat.Html
                msg1.Priority = MailPriority.Normal
                SmtpMail.SmtpServer = "localhost"
                Try
                    SmtpMail.Send(msg1)
                    lbStatus.Text = "Message sent okay"
                Catch
                    lbStatus.Text = "Error sending message"
                End Try
            End Sub
        </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
        <table border="0" align="left" cellpadding="4" cellspacing="0" bgcolor="aliceblue" id="Table1">
            <tr>
                <td width="52" align="left" bgcolor="lightsteelblue"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Subject:</font></strong></td>
                <td><asp:textbox id="tbSubject" runat="server" columns="45"></asp:textbox></td>
            </tr>
            <tr>
                <td width="52" align="left" bgcolor="lightsteelblue"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Message:</font></strong></td>
                <td><asp:textbox id="tbBody" runat="server" textmode="MultiLine" rows="5" columns="35"></asp:textbox></td>
            </tr>
            <tr>
                <td width="52" align="left" bgcolor="lightsteelblue"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font></strong></td>
                <td><asp:button OnClick="btnSend_Click" id="btnSend" runat="server" text="Send Message"></asp:button>&nbsp;<asp:label id="lbStatus" runat="server" Font-Bold="True"></asp:label></td>
            </tr>
        </table>
        <div align="center"><br><br>&nbsp;</div>
        </form>
    </body>
</html>

Rate This Article

How useful was this article?

Not useful A little useful Useful Very useful Everything I needed