How to send mail with out using gmail in asp.net
<table style="width: 587px">
<tr>
<td class="style12">
<div>
<div class="style9" style="height: 43px">Send Your Query Here</div>
<div>
<asp:Label ID="Name" runat="server" Text="Your Name*:" style="font-weight: 700"/><br/>
<asp:TextBox ID="txtName" runat="server" Height="31px" Width="507px"
/>
<asp:RequiredFieldValidator ID="RV1" runat="server"
ControlToValidate="txtName"
ErrorMessage="Please Enter Your Name"
SetFocusOnError="True">*
</asp:RequiredFieldValidator><br />
</div>
<div>
<asp:Label ID="Email" class="eassy" runat="server" Text="Email*:" style="font-weight: 700"/><br/>
<asp:TextBox ID="txtMail" runat="server" Width="507px" Height="28px"/>
<asp:RequiredFieldValidator ID="RV2" runat="server"
ControlToValidate="txtMail"
ErrorMessage="Your Email Address"
SetFocusOnError="True">*
</asp:RequiredFieldValidator><br />
</div>
<div>
<asp:Label ID="Sub" runat="server" Text="Subject*:" style="font-weight: 700"/><br/>
<asp:TextBox ID="txtSubject" runat="server" Width="507px" Height="31px"/>
<asp:RequiredFieldValidator ID="RV3" runat="server"
ControlToValidate="txtSubject"
ErrorMessage="Reason to contact us"
SetFocusOnError="True">*
</asp:RequiredFieldValidator><br />
</div>
<div>
<asp:Label ID="Message" runat="server" Text="Feedback:" style="font-weight: 700"/><br/>
<asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Width="507px"
Height="81px"/>
<asp:RequiredFieldValidator ID="RV4" runat="server"
ControlToValidate="txtMessage"
ErrorMessage="Please write your feedback"
SetFocusOnError="True">*
</asp:RequiredFieldValidator><br />
</div>
<div>
<asp:Button ID="Button1" runat="server" Text="Send Info"
onclick="Button1_Click" />
</div>
<asp:ValidationSummary ID="ValidationSummary1"
runat="server"/>
<asp:Label ID="Label1" runat="server" Font-Size="Large"/>
</div>
<%--<table style="width: 580px">
<tr><td>YourQuestion</td><td>
<asp:TextBox ID="TextBox2" runat="server" Width="245px"></asp:TextBox>
</td></tr>
<tr><td>Comment</td><td>
<asp:TextBox ID="TextBox7" runat="server" Height="55px" TextMode="MultiLine"
Width="245px"></asp:TextBox>
</td></tr>
<tr><td>Your Email Id</td><td>
<asp:TextBox ID="TextBox3" runat="server" Width="245px"></asp:TextBox>
</td></tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click"
ToolTip="Submit" />
</td>
</tr>
</table>--%>
</td>
</tr>
</table>
use name space :-using System.Net.Mail;
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage feedBack = new MailMessage();
feedBack.To.Add("emailId");
feedBack.From = new MailAddress("emailId");
feedBack.Subject = txtSubject.Text;
feedBack.Body = "Sender Name: " + txtName.Text + "<br /><br />Sender Email: " + txtMail.Text + "<br /><br />" + txtMessage.Text;
feedBack.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("emailId", "password");
//Or your Smtp Email ID and Password
smtp.Send(feedBack);
Label1.Text = "Thanks for contacting us";
}
{
MailMessage feedBack = new MailMessage();
feedBack.To.Add("emailId");
feedBack.From = new MailAddress("emailId");
feedBack.Subject = txtSubject.Text;
feedBack.Body = "Sender Name: " + txtName.Text + "<br /><br />Sender Email: " + txtMail.Text + "<br /><br />" + txtMessage.Text;
feedBack.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("emailId", "password");
//Or your Smtp Email ID and Password
smtp.Send(feedBack);
Label1.Text = "Thanks for contacting us";
}

No comments :
Post a Comment