Friday, September 23

Simple code to Send a mail by using Smtp.Host as

Coding Part:-
use namespace:
using System.Net.Mail;

protected void btnSendmail_Click(object sender, EventArgs e)

MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient();
mail.From = new MailAddress(txtEmail.Text);
// mail.To.Add(new MailAddress(txtTo.Text));
mail.To.Add(new MailAddress(""));

mail.Subject = txtSubject.Text;
mail.Body =txtName.Text + txtMessage.Text;
mail.IsBodyHtml = true;
smtp.Host = "";

//smtp.Host = "localhost";

smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "txtEmail.Text";
NetworkCred.Password = "1234";
//NetworkCred.UserName = "";
// NetworkCred.Password = "Password123!";
smtp.UseDefaultCredentials = true;
//smtp.Credentials = NetworkCred;
smtp.Credentials = new System.Net.NetworkCredential("txtEmail.Text", "1234");

smtp.Port = 587;//this is Gmail port for e-mail
//smtp.Port = 25;// this is default port no
smtp.Send(mail);//send an e-mail

lblStatus.Text="Message Sended";
catch(Exception ex)
throw ex;

Design View:-

<div class="col_w420 float_l">
             <h3>Contact Form</h3>
              <div id="cp_contact_form">
              <form runat="server" id="frmSend">
        <h2 style="background-color:Brown; color:Wheat; font-family:Verdana; font-size:14px" align=center>Please enter the following requested 
information below to send us your Message.</h2>
<table align=center>
<td class="style1">
                        <label for="author">
<td><asp:textbox id="txtName" Width="241" Runat="server"></asp:textbox></td>
<td class="style1">
                        <label for="email">
<td><asp:textbox id="txtEmail" Width="241" Runat="server"></asp:textbox></td>
<td class="style1">
                        <label for="subject">
<td><asp:textbox id="txtSubject" Width="241" Runat="server"></asp:textbox></td>
<td colSpan="2" >
                        <label for="text">
<td align="center" colSpan="2" width=100%><asp:textbox id="txtMessage" Width="99%" 
                            Runat="server" Height="99px" TextMode="MultiLine" MaxLength="400"></asp:textbox></td>
<td colSpan="2">&nbsp;</td>
<td align=center class="style1"><asp:button id="btnSendmail" Runat="server" Text="Send " 
<td align=center><asp:button id="btnReset" Runat="server" Text="Reset" OnClick="btnReset_Click"></asp:button></td>
<td colSpan="2"><asp:label id="lblStatus" Runat="server" EnableViewState="False"></asp:label></td>

No comments:

Post a Comment

Please don't spam, spam comments is not allowed here.

shibashish mohanty