0

I need to send email along with subject and message.I went through many blogs,but most of them used ajax and PHP. Is there any means to send mail only using ajax or JavaScript alone???I don't want to use mailto in html..IF there is any other means to do please help me!!

Thanks in advance :)

2
  • Do you count Node.js, or just client-side? Commented Jan 13, 2014 at 11:01
  • Node.Js won't be a problem!!All i want is that i don't want to use PHP,rest anything will do!!But i don't have much info about node.js Commented Jan 13, 2014 at 11:07

5 Answers 5

2

You can use:

var link = "mailto:[email protected]"
         + "[email protected]"
         + "&subject=" + escape("This is my subject")
         + "&body=" + escape("This is body")
;

window.location.href = link;

You can use this library for making ajax calls to send emails.

Updated-C# code for sending mails:

SmtpClient smtpClient = new SmtpClient("mail.MyWebsiteDomainName.com", 25);

smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "myIDPassword");
        smtpClient.UseDefaultCredentials = true;
        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtpClient.EnableSsl = true;
        MailMessage mail = new MailMessage();


        //Setting From , To and CC
        mail.From = new MailAddress("info@MyWebsiteDomainName", "MyWeb Site");
        mail.To.Add(new MailAddress("info@MyWebsiteDomainName"));
        mail.CC.Add(new MailAddress("[email protected]"));


 smtpClient.Send(mail);
Sign up to request clarification or add additional context in comments.

4 Comments

Well then..i don't want to use php...how to send email using c#??
@AshishKumar:you need to register for Mandrill to get an API key
do i need to paste this code within my ashx page and pass data from html page through ajax??
Yes in the ashx.cs file which handles send request.
0

JavaScript is of course client based so doesn't have the capabilities as say C# or PHP on the server. To send email, without calling some server-side code, you are basically limited to mailto option only.

Comments

0

I don't know any possibility to send mail from javascript without using your local mail client and mailto except using third party apis:

Here is a tutorial that uses Ajax to send mails but you have to get a mandrill api key first:

https://medium.com/design-startups/b53319616782

1 Comment

its the same link as the other answer.
0

For sending email you required some smtp server as JavaScript is client script language

Comments

0

Nodemailer looks like a nice Node.js mailing library. I didn't test it though.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.