Send out email in code behind (C#) : Email « Components « ASP.Net

ASP.Net
1. ADO.net Database
2. Ajax
3. Asp Control
4. Collections
5. Components
6. Data Binding
7. Development
8. File Directory
9. HTML Control
10. Language Basics
11. Login Security
12. Mobile Control
13. Network
14. Page
15. Request
16. Response
17. Server
18. Session Cookie
19. Sitemap
20. Theme Style
21. User Control and Master Page
22. Validation by Control
23. Validation by Function
24. WebPart
25. WPF
26. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » Components » Email 
Send out email in code behind (C#)

<%@ Page language="c#" src="IssueReporter.aspx.cs" AutoEventWireup="false" Inherits="IssueReporter.IssueReporter" %>
<HTML>
  <body>
    <form id="Form1" method="post" runat="server">
      <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 54px" runat="server" Font-Names="Verdana" Font-Size="X-Small">Your Name:</asp:Label>
      <asp:TextBox id="txtComment" style="Z-INDEX: 107; LEFT: 176px; POSITION: absolute; TOP: 112px" runat="server" Width="384px" Height="112px" TextMode="MultiLine" Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox>
      <asp:TextBox id="txtSender" style="Z-INDEX: 106; LEFT: 176px; POSITION: absolute; TOP: 80px" runat="server" Width="259px" Height="24px" Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox>
      <asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 86px" runat="server" Font-Names="Verdana" Font-Size="X-Small">Your Email:</asp:Label>
      <asp:Label id="Label3" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 118px" runat="server" Width="104px" Height="16px" Font-Names="Verdana" Font-Size="X-Small">Comment:</asp:Label>
      <asp:CheckBox id="chkPriority" style="Z-INDEX: 104; LEFT: 32px; POSITION: absolute; TOP: 240px" runat="server" Width="416px" Height="24px" Text="Please Reply Immediately!" Font-Names="Verdana" Font-Size="X-Small"></asp:CheckBox>
      <asp:TextBox id="txtName" style="Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 48px" runat="server" Width="258px" Height="24px" Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox>
      <asp:Button id="cmdSend" style="Z-INDEX: 108; LEFT: 32px; POSITION: absolute; TOP: 288px" runat="server" Width="88px" Height="24px" Text="Send"></asp:Button>
      <asp:Label id="lblResult" style="Z-INDEX: 109; LEFT: 40px; POSITION: absolute; TOP: 352px" runat="server" Width="432px" Height="72px" Font-Names="Verdana" Font-Size="X-Small"></asp:Label>
    </form>
  </body>
</HTML>

<%--
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

namespace IssueReporter
{
  /// <summary>
  /// Summary description for IssueReporter.
  /// </summary>
  public class IssueReporter : System.Web.UI.Page
  {
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.TextBox txtComment;
    protected System.Web.UI.WebControls.TextBox txtSender;
    protected System.Web.UI.WebControls.Label Label2;
    protected System.Web.UI.WebControls.Label Label3;
    protected System.Web.UI.WebControls.CheckBox chkPriority;
    protected System.Web.UI.WebControls.TextBox txtName;
    protected System.Web.UI.WebControls.Button cmdSend;
    protected System.Web.UI.WebControls.Label lblResult;
  
    private void Page_Load(object sender, System.EventArgs e)
    {
      // Put user code to initialize the page here
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }
    
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
      this.cmdSend.Click += new System.EventHandler(this.cmdSend_Click);
      this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void cmdSend_Click(object sender, System.EventArgs e)
    {
      MailMessage msg = new MailMessage();
      msg.Subject = "Issue Report";
      msg.Body = "Submitted By: " + txtName.Text + "\n";
      msg.Body += txtComment.Text;
      msg.From = txtSender.Text;

      msg.To = "yourname@youremailserver.com";

      if (chkPriority.Checkedmsg.Priority = MailPriority.High;

      SmtpMail.SmtpServer = "localhost";
      SmtpMail.Send(msg);

      lblResult.Text="Message sent to SMTP service.";
    }
  }
}

--%>
           
       
Related examples in the same category
1. Simplest Way of Sending Email from Gmail
2. Send out an Email
3. Send email with attached file
4. Send email out through asp:form
5. Send email to all employees in database
6. Send email with html form message
7. Email message in a html format
8. Email form with cc and bcc
9. Email with priority
10. Send email function
11. Email with pictures
12. Email with attachment
13. Send email with more than one attachments
14. Send out an email in case of page error
15. Send an email
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.