Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can anyone give me example on how to send email using HTML code or javascript code.
Any links or sample program?

Thanks,
Sampath.
Posted
Updated 2-Jun-11 21:36pm
v2

If you are using Asp.Net then use Javascript Ajax postback and send email from server side. You can achieve this using XmlHttpObject or JQuery. In case you are working on pure HTML and Javascript application then try SendGrid REST API. Below is SendGrid website url.


http://sendgrid.com/documentation/display/api/Web[^]

Sample code is like below.

XML
<script language="javascript" type="text/javascript">
    function Sendmail() {

        if (document.getElementById("TxtFrom").value == "" || document.getElementById("TxtTo").value == "" || document.getElementById("TxtSub").value == "" || document.getElementById("TxtBody").value == "") {
            alert("Fields cant not be empty!");
        }
        else {
            var restURL = "https://sendgrid.com/api/mail.send.xml?api_user=UserRegistrationEmail@domain.com&api_key=ApiKeyValue&to=" + document.getElementById("TxtTo").value + "&toname=Destination&subject=" + document.getElementById("TxtSub").value + "&html=" + document.getElementById("TxtBody").value + "&from=" + document.getElementById("TxtFrom").value;
            window.open(restURL, 'sendgrid', 'width=400,height=200');

            //window.location.href = maill;
            alert("Mail sent successfully!");
        }
    }
</script>
 
Share this answer
 
You can't do that by HTML. use ASP.NET

Sending Email in ASP.NET[^]
 
Share this answer
 
Comments
sampath1750 3-Jun-11 3:09am    
Is it possible for javascript or not
Toniyo Jackson 3-Jun-11 3:13am    
No. Not possible
Check the same discussion here[^]
 
Share this answer
 
You cannot directly send email via html or javascript.
 
Share this answer
 
This[^] should help.

Or This[^].

Here too[^].

In fact a quick google search revealed several links that may be of interest, (43,100,000 of them in fact).
 
Share this answer
 
You can do this by using cdo.Message object of vbscript to send mail..
 
Share this answer
 
v2

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