none
How to send Email notification sharepoint 2010 using Javascript ? RRS feed

  • Question

  • Hi,

          I want to send email notification using javascript (or) Ecmascript in sharepoint 2010.

    Thanks in advance

    Regards

    Narasimman

    Wednesday, July 3, 2019 10:58 AM

All replies

  • Hi SimhaVL,

    Can you check the link below, may be it helps..

    http://geekswithblogs.net/ThorvaldBoe/archive/2014/07/03/sending-email-with-sharepoint-and-jquery.aspx

    Wednesday, July 3, 2019 12:05 PM
  • Below code i tried way back & worked like a charm:

    function processSendEmail() { if ($("#empEmailId").val() != null) { var userEmaiId = $("#empEmailId").val(); } else { alert("EmailId Should not be empty"); } var From = ''; var To = userEmaiId; var Body = 'You have been successfully submitted the data to List'; var SubjectOfEmail = 'Email Notification Using REST API'; sendEmailNotification(From, To, Body, SubjectOfEmail); } function sendEmailNotification(From, To, Body, SubjectOfEmail) { hostWebUrl = decodeURIComponent(manageQueryStringParameter('SPHostUrl')); var constructedURL = appWebUrl + "/_api/SP.Utilities.Utility.SendEmail"; $.ajax({ contentType: 'application/json', url: constructedURL, type: "POST", data: JSON.stringify({ 'properties': { '__metadata': { 'type': 'SP.Utilities.EmailProperties' }, 'From': From, 'To': { 'results': [To] }, 'Body': Body, 'Subject': SubjectOfEmail } } ), headers: { "Accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() }, success: function (data) { alert('Email Sent Successfully'); }, error: function (err) { alert('Error in sending Email: ' + JSON.stringify(err)); } }); }

    Thanks & Regards,


    sharath aluri


    Wednesday, July 3, 2019 12:49 PM
  • Hi Narasimman,

    Unfortunately, SharePoint 2010 can't provide the REST API "/_api/SP.Utilities.Utility.SendEmail" to send email using JavaScript code directly.

    As a workaround, we can create a custom list, and using workflow to send email, and using JavaScript code with ListData.svc service to add item to the list, to trigger the send email workflow to achieve this requirement.

     //create
    var url = "/teamsite/_vti_bin/ListData.svc/MyContacts";
    var contact = {
    	FirstName: "Arnie",
    	Title: "Dell",
    	WorkCity: "Lund"
    };
    var body = JSON.stringify(contact);
    $.ajax({
    	 type: "POST",
    	 url: url,
    	 contentType: 'application/json',
    	 processData: false,
    	 data: body,
    	 success: function () {
    	   alert('Contact Saved.');
    	 }
    });

    The following articles for your reference.

    https://chuvash.eu/2011/12/15/update-list-items-with-listdata-svc/

    https://spjsblog.com/2010/06/16/send-email-with-javascript-with-the-help-of-a-workflow-in-a-dedicated-send-email-list/

    Or we can create a custom web service with Server Object Model to achieve the send email, then consume the web service using JavaScript from the client side.

    https://www.c-sharpcorner.com/blogs/how-to-create-a-custom-web-service-in-sharepoint-2010

    https://www.c-sharpcorner.com/blogs/send-email-in-sharepoint-2010

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, July 4, 2019 2:03 AM
    Moderator
  • Hi sharath,

    Thanks for your code.

    In SharePoint 2010 can't provide the REST API "/_api/SP.Utilities.Utility.SendEmail" to send email using JavaScript code directly.

    so is there any posibility in ECMA script or SPService ?


    • Edited by SimhaVL Thursday, July 4, 2019 8:13 AM Updated
    Thursday, July 4, 2019 8:09 AM
  • hi Dennis,

    Thanks for your reference.

    Is there code in ECMA script or SPService to do ? without workflow.

    Thursday, July 4, 2019 8:12 AM
  • Hi,

    Unfortunately, per my knowledge, there is not an OOTB JSOM API to achieve it in SharePoint 2010.

    I suggest you use the two workarounds in my reply above to achieve it.

    Best Regards,

    Dennis 


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, July 4, 2019 8:35 AM
    Moderator
  • Instead of that why can't you use alert me option on a SharePoint page with SPServices ?

    Below article for more reference:

    https://www.itidea.nl/index.php/simple-alert-me-option-on-a-sharepoint-page-with-spservices/

    Thanks & Regards,


    sharath aluri

    Thursday, July 4, 2019 4:29 PM
  • Hi,

    Would you please provide us with an update on the status of your issue?

    Best Regards,
    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, July 9, 2019 8:10 AM
    Moderator
  • Hi narasimman,

    Any update?

    If the replies helps you, please mark the reply as answer, it will make others who stuck with the similar issue easier to search for valid solutions in this forum.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, July 16, 2019 3:07 AM
    Moderator