Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
Mail sending code
ashok kumar
11y
989
1
Reply
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Net" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sendmail();
}
}
public void sendmail()
{
try
{
string subject = Request.Form.GetValues("
eSubject")[0].ToString();
string arriaval_day = Request.Form.GetValues("
Arrival_Day")[0].ToString();
string duratoin = Request.Form.GetValues("
Duration")[0].ToString();
string adults = Request.Form.GetValues("
Adults")[0].ToString();
string hotel = Request.Form.GetValues("hotel"
)[0].ToString();
string name = Request.Form.GetValues("Name")
[0].ToString();
string EmailID = Request.Form.GetValues("
EmailID")[0].ToString();
string Phone = Request.Form.GetValues("Phone"
)[0].ToString();
string Country = Request.Form.GetValues("
Country")[0].ToString();
string Requirements = Request.Form.GetValues("
Requirements")[0].ToString();
string hReferer = Request.Form.GetValues("
hReferer")[0].ToString();
StringBuilder sbBody = new StringBuilder();
StringBuilder sbBodyAdmin = new StringBuilder();
sbBody.Append("<div><p style='padding-left:20px; font-size:20px;'>Thank you for contacting us. Our Executive will contact you shortly." +
"Your Registration Details are as:</p><div style='width: 70%;' align='center'><table style='width:60%; text-align:left;' border='1px'>" +
"" +
"<tr><td style='width:30%'>Name </td><td>" + name + "</td>" +
"</tr><tr><td style='width:30%'>Email </td><td>" + EmailID + "</td></tr>" +
"<tr><td style='width:30%'>Phone </td><td>" + Phone + "</td></tr>" +
"<tr><td style='width:30%'>Country </td><td>" + Country + "</td></tr>" +
"<tr><td style='width:30%'>Requirements </td><td>" + Requirements + "</td></tr></table></div><br />" +
"<p style='padding-left:20px; font-size:20px;'>Note: For More Details Please contact us at
[email protected]
or 022-234532</p></div>");
MailMessage ms = new System.Net.Mail.MailMessage();
ms.From = new MailAddress("
iabc@gmail.
com
", "Best");
ms.To.Add(new MailAddress(EmailID));
ms.Subject = "Registration for " + subject;
ms.Body = sbBody.ToString();
ms.BodyEncoding = Encoding.UTF8;
ms.IsBodyHtml = true;
SmtpClient mailclient = new SmtpClient();
mailclient.Host = "
smtp.gmail.com
";
mailclient.Port = 587;
mailclient.
UseDefaultCredentials = false;
mailclient.EnableSsl = true;
mailclient.Credentials = new System.Net.NetworkCredential(
"
[email protected]
",
"abc");
mailclient.Send(ms);
Response.Write(EmailID);
// sending mail to admin
sbBodyAdmin.Append("<div><p style='padding-left:20px; font-size:20px;'>" +
"Requested Registration Details are as:</p><div style='width: 70%;' align='center'><table style='width:60%; text-align:left;' border='1px'>" +
"" +
"<tr><td style='width:30%'>Name </td><td>" + name + "</td>" +
"</tr><tr><td style='width:30%'>Email </td><td>" + EmailID + "</td></tr>" +
"<tr><td style='width:30%'>Phone </td><td>" + Phone + "</td></tr>" +
"<tr><td style='width:30%'>Country </td><td>" + Country + "</td></tr>" +
"<tr><td style='width:30%'>Requirements </td><td>" + Requirements + "</td></tr></table></div><br />" +
"<p style='padding-left:20px; font-size:20px;'></p></div>");
MailMessage msAdmin = new MailMessage();
msAdmin.From = new MailAddress(EmailID, name);
//msAdmin.To.Add(new MailAddress(""));
msAdmin.To.Add(new MailAddress("
xyzr@
gmail.com
"));
// msAdmin.CC.Add(new MailAddress("
[email protected]
"
));
msAdmin.Subject = "Registration for " + subject;
msAdmin.Body = sbBodyAdmin.ToString();
msAdmin.BodyEncoding = Encoding.UTF8;
msAdmin.IsBodyHtml = true;
SmtpClient mailclientAdmin = new SmtpClient();
mailclientAdmin.Host = "
smtp.gmail.com
";
mailclientAdmin.
UseDefaultCredentials = false;
mailclientAdmin.Port = 587;
mailclientAdmin.EnableSsl = true;
mailclientAdmin.Credentials = new System.Net.NetworkCredential(
"
[email protected]
",
"abc");
mailclient.Send(msAdmin);
// Response.Redirect("
http://
findindiatours.com/brand/
thanks.asp
", false);
}
catch (Exception ex)
{
//Response.Redirect("
http://
findindiatours.com/brand/
thanks.asp
", false);
}
}
</script>
<html>
<head>
<title>getting</title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to read in numbers from a text box?
C# listbox exception