• #11601
    Salesforce | Naman Naman #188

    How to send email using javascript on vf page?

    How to send email using javascript on vf page?


    Salesforce | Abhinav Abhinav #337

    Yes you can do with Salesforce AJAX Toolkit. You can write something like this in your JavaScript. You can update the SendMail function with all the required parameters and call from the onclick action of the button.

    <apex:page >
    <script type=”text/javascript”>
    var __sfdcSessionId = ‘{!GETSESSIONID()}’;
    <script src=”../../soap/ajax/34.0/connection.js” type=”text/javascript”></script>
    <script type=”text/javascript”>
    function SendMail() {
    try {
    sforce.connection.sessionId = “{!$Api.Session_ID}”;
    var message = new sforce.SingleEmailMessage();
    message.replyTo = “[email protected]”;
    message.targetObjectId = “xxxxxxxxxxxxxxxxx”;
    message.templateId = “xxxxxxxxxxxxxxxxx”;
    message.saveAsActivity = false;
    message.plainTextBody = “this test went through ajax”;
    var result = sforce.connection.sendEmail([message]);
    if(result[0].success == ‘true’) {
    alert(“Mail sent successfully”);
    } else {
    alert(“I had a booboo.”);
    }catch(e) {
    alert(“Error Occurred: \n\n” + (e.message||e));




    You can create simple js method

    <script type="text/javascript">
    function sendEmail() {
    // put code here

    and add to command button onclick event


    And why you want implement requirement without controller?

Viewing 3 posts - 1 through 3 (of 3 total)

Please to reply to this topic.


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?