Sending E- Mails in ASP.NET - Feedback E-mail
Sending E-Mails through web sites can be seen in most of the web sites in nowadays. Here I am interested in creating a form and bind it to -Mail.
There can be many categories of sending E-Mail. Here I have discussed about 2 categories.
Next is to write the event for "Send Feedback" Button.
Here the email will be sent to ""admin@dotnettips4u.com" as a Feedback.
Next I will show how to send an Acknowledgement E-Mail.
There can be many categories of sending E-Mail. Here I have discussed about 2 categories.
- Sending feedback to the web site owner.
- Acknowledgement E-Mail when a query or question is submitted through the web site.
Feedback Email
First create a web form.
Form |
Then create a Simple form as below.
Feedback Form |
Code Snippet - ".aspx"
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="SendEmail.aspx.cs" Inherits="SendEmail"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <table style="width:100%;">
- <tr>
- <td>
- <asp:Label ID="Label4" runat="server" style="font-weight: 700; color: #FF0000"
- Text="Contact Details"></asp:Label>
- </td>
- <td>
- </td>
- </tr>
- <tr>
- <td>
- </td>
- <td>
- </td>
- </tr>
- <tr>
- <td>
- <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
- </td>
- <td>
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:Label ID="Label2" runat="server" Text="E-Mail Address"></asp:Label>
- </td>
- <td>
- <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:Label ID="Label3" runat="server" Text="Comments"></asp:Label>
- </td>
- <td>
- <asp:TextBox ID="TextBox3" runat="server" Height="112px" TextMode="MultiLine"
- Width="284px"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
- Text="Send Feedback" />
- </td>
- <td>
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <asp:Label ID="Label5" runat="server"></asp:Label>
- </td>
- </tr>
- </table>
- </form>
- <p>
- </p>
- </body>
- </html>
Next is to write the event for "Send Feedback" Button.
Code Snippet - ".aspx.cs"
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Net.Mail;
- using System.Net.Security;
- public partial class SendEmail : System.Web.UI.Page
- {
- protected void Button1_Click(object sender, EventArgs e)
- {
- MailMessage mailMsg = new MailMessage();
- mailMsg.From = new MailAddress(TextBox2.Text);
- mailMsg.To.Add("admin@dotnettips4u.com");
- mailMsg.IsBodyHtml = true;
- mailMsg.Subject = "Contact Details";
- mailMsg.Body = "Contact Details" + "<b>Name:</b>" + TextBox1.Text + " <br/> <b>Email - address :</b>" + TextBox2.Text + "<br/> <b>Comments :</b>" + TextBox3.Text;
- SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
- mailMsg.Priority = MailPriority.Normal;
- smtp.Credentials = new System.Net.NetworkCredential("admin@dotnettips4u.com","yourPassword");
- smtp.Timeout = 25000;
- smtp.EnableSsl = true;
- smtp.Send(mailMsg);
- Label5.Text = "Thank you. Your contact details and feed back has been submitted.";
- }
- }
Here the email will be sent to ""admin@dotnettips4u.com" as a Feedback.
Next I will show how to send an Acknowledgement E-Mail.
No comments:
Post a Comment