Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to send Email using javascript
Posted

You can't send an e-mail directly with Javascript as it is only client side and you need the server side to do that.

Of course you can use "mailto:" as a workaround.

A small google search has given me lot's of results, even one question in CP: How to send Mail using Javascript[^]

And others:
http://www.roseindia.net/answers/viewqa/PHP/14717-send-mail-using-JavaScript.html[^]

http://stackoverflow.com/questions/271171/sending-emails-with-javascript[^]

Searching Google is a good starting point...
 
Share this answer
 
Comments
madhu.gone 30-Aug-12 2:52am    
ok
mail to does not work to send a mail if u r sending mail uisng Asp .net

then
// use this code to send mail but it only work with gmail if you r working with other then change this code nly port no
objSMTPClient.Port = 587;


C#
using System.Net.Mail;
using System.Text;




protected void Submit_Click(object sender, EventArgs e)
{
if (Txt1.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The company name";
}
else if (TextBox2.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The Full name";
}
else if (TextBox3.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The EMail";
}
else if (TextBox4.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The Contact no";
}
else if (TextBox5.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The dESCRIPTION";
}
else
{
String str;
str = "Full Name :" + Txt1.Text.ToUpper();
str = str + "Company : " + TextBox2.Text;
str = str + "Email : " + TextBox3.Text;
str = str + "Contact no : " + TextBox4.Text;
str = str + "Description : " + TextBox5.Text;

try
{
Email("dksingh6788@gmail.com", "devendrak@fitatechnologies.com", str);
Response.Redirect("Thanku.aspx");

}
catch { }
}

}
public bool Email(string strFrom, string strTo, string strMessage)
{

try
{
if (strFrom.Trim() != "" && strTo.Trim() != "" && strFrom.Trim() != null && strTo.Trim() != null)
{
System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage();
objMailMessage.Body = strMessage;
objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
objMailMessage.IsBodyHtml = false;
objMailMessage.From = new MailAddress(strFrom, "One Ghost", System.Text.Encoding.UTF8);
objMailMessage.To.Add(new MailAddress(strTo));
//objMailMessage.CC.Add(new MailAddress(strTo));
objMailMessage.Subject = "Registration Request";
objMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
objMailMessage.Priority = MailPriority.High;
//if (FileUpload1.HasFile)
//{
// objMailMessage.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
//}

try
{

System.Net.Mail.SmtpClient objSMTPClient = new System.Net.Mail.SmtpClient();
objSMTPClient.Credentials = new System.Net.NetworkCredential(strFrom, "you gmail password");// please insert gmail password
//objSMTPClient.Credentials = objSMTPClient.Credentials.GetCredential(objSMTPClient.Host, objSMTPClient.Port, "Digest");
objSMTPClient.Port = 587;
objSMTPClient.Host = "smtp.gmail.com";
objSMTPClient.EnableSsl = true;
//objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSMTPClient.Send(objMailMessage);

}
catch (Exception ex)
{
return false;
}
}
}

catch (Exception ex)
{
return false;
}
return true;

}
 
Share this answer
 
Comments
Devendra 1988 31-Aug-12 0:31am    
how to devote this i am currently using this its works permanently ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900