Send an email : Email « Components « ASP.Net






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

1.Simplest Way of Sending Email from Gmail
2.Send out email in code behind (C#)
3.Send out an Email
4.Send email with attached file
5.Send email out through asp:form
6.Send email to all employees in database
7.Send email with html form message
8.Email message in a html format
9.Email form with cc and bcc
10.Email with priority
11.Send email function
12.Email with pictures
13.Email with attachment
14.Send email with more than one attachments
15.Send out an email in case of page error