<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Net" %>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sendmail();
}
}
public void sendmail()
{
try
{
string subject = Request.Form.GetValues("
string arriaval_day = Request.Form.GetValues("
string duratoin = Request.Form.GetValues("
string adults = Request.Form.GetValues("
string hotel = Request.Form.GetValues("hotel"
string name = Request.Form.GetValues("Name")
string EmailID = Request.Form.GetValues("
string Phone = Request.Form.GetValues("Phone"
string Country = Request.Form.GetValues("
string Requirements = Request.Form.GetValues("
string hReferer = Request.Form.GetValues("
StringBuilder sbBody = new StringBuilder();
StringBuilder sbBodyAdmin = new StringBuilder();
sbBody.Append("
Thank you for contacting us. Our Executive will contact you shortly." +
"Your Registration Details are as:
| Name | " + name + " | " +
| " + EmailID + " | |
| Phone | " + Phone + " |
| Country | " + Country + " |
| Requirements | " + Requirements + " |
" +
"
Note: For More Details Please contact us at
admin@abc.com or 022-234532MailMessage ms = new System.Net.Mail.MailMessage();
ms.From = new MailAddress("iabc@gmail.
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.
mailclient.EnableSsl = true;
mailclient.Credentials = new System.Net.NetworkCredential(
mailclient.Send(ms);
Response.Write(EmailID);
// sending mail to admin
sbBodyAdmin.Append("
" +
"Requested Registration Details are as:
| Name | " + name + " | " +
| " + EmailID + " | |
| Phone | " + Phone + " |
| Country | " + Country + " |
| Requirements | " + Requirements + " |
" +
"
MailMessage msAdmin = new MailMessage();
msAdmin.From = new MailAddress(EmailID, name);
//msAdmin.To.Add(new MailAddress(""));
msAdmin.To.Add(new MailAddress("xyzr@
// msAdmin.CC.Add(new MailAddress("abc@yahoo.in"
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.
mailclientAdmin.Port = 587;
mailclientAdmin.EnableSsl = true;
mailclientAdmin.Credentials = new System.Net.NetworkCredential(
mailclient.Send(msAdmin);
// Response.Redirect("http://
}
catch (Exception ex)
{
//Response.Redirect("http://
}
}
venkata kumarPosted Feb 27, 2013, 10:57 PM
try this
string senderEmailId = "[email protected]";
string SenderContactName = "Ravi";
string senderPassword = "password";
string Subject = "CreditInvoice";
string Body = "Find Enclosed Attachment File";
if ((Subject.ToString().Trim() == string.Empty) ||
(Body.ToString().Trim() == string.Empty))
{
return "Email Subject or Email Body is blank";
}
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
// sender name and email id
msg.From = new System.Net.Mail.MailAddress(senderEmailId, SenderContactName);
// Receiver email id
msg.To.Add(new System.Net.Mail.MailAddress("[email protected]"));
msg.Subject = Subject;
msg.Priority = System.Net.Mail.MailPriority.High;
msg.IsBodyHtml = true;
msg.Body = Body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com");
client.Credentials = new NetworkCredential(senderEmailId, senderPassword);
client.EnableSsl = true;
client.Send(msg);
return "Success";