You are Here: FAQ ->Scripting and Programming Languages->ASP.NET->Article #7


Sending e-mails using ASP.Net


For Microsoft® packages with .NET/MSSQL access only!Microsoft® Packages with .NET/MSSQL Only!
      This includes:
          arrow 1&1 MS Business
          arrow 1&1 MS Developer
      This DOES NOT include:
          not 1&1 MS Beginner
          not 1&1 MS Home




In order to be able to send e-mail using ASP.net, you have to use the name space System.Web.Mail and the appropriate class MailMessage

The following is a sample:
            
<% @Import Namespace="System.Web.Mail" %>
<script language="vb" runat="server">

Sub contactUS_Click(sender as Object, e as EventArgs)

  'Create an instance of the MailMessage class
  Dim objMM as New MailMessage()

  objMM.To = "info@1and1.com"
  objMM.From = email.Text

  'If you want to CC this e-mail to someone else
  'objMM.Cc = "support@1and1.com"

  'e-mail format. Can be Text or Html
  objMM.BodyFormat = MailFormat.Text

  'Set the priority - options are High, Low, and Normal
  objMM.Priority = MailPriority.Normal

  'Set the subject
  objMM.Subject = "1&1 Contact US"

  'Set the body
  objMM.Body = message.Text
	
  'Smtp Server
  SmtpMail.SmtpServer = "mrelay.perfora.net"
  
  'Send the message
  SmtpMail.Send(objMM)

  panelSendEmail.Visible = false
  panelMailSent.Visible = true

End Sub

</script>

<html>
<body>
  <asp:panel id="panelSendEmail" runat="server">
    <form runat="server">
      <h2>CONTACT US FORM</h2>

      <b>Your Name:</b>
      <asp:textbox id="name" runat="server" />
      <br>

      <b>Your Email Address:</b>
      <asp:textbox id="email" runat="server" />
      <p>

      <b>Your Message:</b><br>
      <asp:textbox id="message" TextMode="MultiLine"
                      Columns="40" Rows="10" runat="server" />
      <p>

      <asp:button runat="server" id="contact_us" Text="Contact" OnClick="contactUS_Click" />
    </form>
  </asp:panel>


  <asp:panel id="panelMailSent" runat="server" Visible="False">
    An e-mail has been sent. We will contact you soon!
  </asp:panel>
</body>
</html>
          



Disclaimer: 1&1 provides the scripts and related information on this page as a courtesy, subject to 1&1's General Terms and Conditions of Service (the "GT&C"). As set forth in more detail in the GT&C, the scripts and information are provided "as-is", without any warranty, and 1&1 is not liable for any damages resulting from your use of the scripts or information.



Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not useful at all):
1 2 3 4 5