Send an email
<%@ Page Language="VB" %>
<script runat="server">
Sub Button1_Click(sender As Object, e As EventArgs)
Label1.Text = SendMail("Feedback form", TextBox1.Text, TextBox2.Text)
End Sub
Function SendMail(Subject As String, FromAddress As String, Message As String) As String
' Build a MailMessage
Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mailMessage.From = "someone@example.com"
mailMessage.To = "someone@example.com"
mailMessage.Subject = "Sending an e-mail from a web page"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
' TODO: Set the mailMessage.Body property
mailMessage.Body = Message
System.Web.Mail.SmtpMail.SmtpServer = "localhost"
System.Web.Mail.SmtpMail.Send(mailMessage)
SendMail = "Your message was sent to " & mailMessage.To
End Function
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
Your email address:
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
Your message:
<asp:TextBox id="TextBox2" runat="server" TextMode="MultiLine"></asp:TextBox>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Send"></asp:Button>
</p>
<p>
<asp:Label id="Label1" runat="server"></asp:Label>
</p>
</form>
</body>
</html>
Related examples in the same category