1

I'm trying to create a form of "Contact us" with ausnto fields and message the cuestios is that the customer wants that form send the message to a specific mail and the sender information, it also tells me that has the SMTP protocol active but not how to use it ... I am new to this topic sharepoint and have not much experience in this I need please help me

Thank you

1
  • request you to share, by which way you are trying to contact us form? Server side webpart, client side scripts ? Also please update which version of SharePoint... Commented Oct 28, 2016 at 6:09

1 Answer 1

1

There are different ways to send mail through SharePoint depending on version of SharePoint.

  1. SP 2010 - Sending via server side code using SPUtility class( provided your SharePoint farm has correct SMTP settings updated via central administration) or via System.Net.Mail. Refer below link http://sharepoint-community.net/profiles/blogs/sending-email-programmatically-in-sharepoint

  2. SP 2013/2016 - you can also use above method but here another option coudle be sending mail via REST API from client side. below is sample code for quick reference.

    function sendEmail(from, to, body, subject) {

    var appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));
    var urlTemplate = appweburl + "/_api/SP.Utilities.Utility.SendEmail";
    $.ajax({
        contentType: 'application/json',
        url: urlTemplate,
        type: "POST",
        data: JSON.stringify({
            'properties': {
                '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
                'From': from,
                'To': { 'results': [to] },
                //'CC': { 'results': [cc]}, //Maybe you want to include a CC address?
                'Body': body,
                'Subject': subject
            }
        }
      ),
        headers: {
            "Accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
           alert("An email was sent.");
        },
        error: function (args) {
           alert("We had a problem and an email was not sent.");
        }
    }); }
    

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.