Geeks With Blogs
Thorvald Bøe
Want to send email from SharePoint using jQuery? No problem!

No need to create workflows or set up SMTP servers, just use this simple function:

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

var siteurl = _spPageContextInfo.webServerRelativeUrl;

var urlTemplate = siteurl + "/_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] },
           'Body': body,
           'Subject': subject
       }
   }
 ),
   headers: {
       "Accept": "application/json;odata=verbose",
       "content-type": "application/json;odata=verbose",
       "X-RequestDigest": $("#__REQUESTDIGEST").val()
   },
   success: function (data) {
      alert("Eposten ble sendt");
   },
   error: function (err) {
       alert(err.responseText);
       debugger;
   }
});
}

This works nicely on SharePoint online, apparently it works on OnPremise as well. Just note that the recipient is limited to a valid SharePoint user for security reasons.
Posted on Thursday, July 3, 2014 3:58 PM jquery , sharepoint , email | Back to top


Comments on this post: Sending email with SharePoint and jQuery

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Thanks, this is very helpful.
Left by Excellent ! on Dec 09, 2014 8:14 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Is it possible to include attachments?
Left by bhavan on Dec 23, 2014 8:14 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Unfortunately, it seems like it is not possible to include attachments. You will need to use other tools for that.

-Thorvald
Left by Thorvald on Jan 02, 2015 1:50 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
It is not working in SharePoint Online
Left by Vino on Feb 16, 2015 9:41 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Vino, it does work on SharePoint Online.
However, there is a limitation of sending email only to users on your site.
Can you be more specific to what is not working for you?

Thorvald
Left by Thorvald on Feb 18, 2015 10:34 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
i have a site which is access for the anonymous users. One of the pages in this site having a form , that is to be filled by anonymous users.
I need to send mail to such anonymous user when they register the form.
Left by Dheeraj on Apr 06, 2015 10:08 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Dheeraj,
you don't say much about your environment, but I am going to assume we are still talking about SharePoint.

If an anonymous user fills out a form including their email address, and you want to send them an email, you will have different options depending on whether you are in SharePoint Online or SharePoint OnPremise.

In Online, it is not possible to send email to unregistered users using the method I described above, only registered users can receive email. But there are of course workaraounds for this. You can check out third party services for sending email, or you can implement your own in e.g. a free azure web site.

In OnPremise, you would have more options, you could e.g. make a farm solution that utilizes the SharePoint api or even a custom assembly that sends the email.

Good luck! :)
Left by Thorvald on Apr 07, 2015 10:52 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
How to put cc in this? It is throwing an exception that cc property is not present in senemail.
Left by Arnab Chatterjee on Jun 04, 2015 1:32 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
I've put that identical code into a calculated column, but it fails on the $.ajax code. Details at http://stackoverflow.com/questions/30905998/sending-email-through-ajax-calculated-column. Any suggestions on what I've done wrong?
Left by Steve on Jun 19, 2015 10:15 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
The only thing I can think of, is that the code in this post assumes that you have already included your jQuery reference somewhere in a content editor web part, master page or similar. If you haven't, the code will fail on the first "$" call ($ is undefined).

Apart from that, I can see your stackoverflow question was answered, and I think his suggestions were good. I haven't thought of using snippets in SharePoint before - I'll actually try it out myself, seems more convenient than SharePoint designer.

-T
Left by Thorvald on Jun 22, 2015 8:25 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
I tried this on SharePoint Online and it worked partially. I was able to receive emails where the "From" address was not no-reply@shrepoint.com but actual users from our organization. But when we reply to these emails from outlook they are converted to "no-reply@sharepoint.com" and not the "From" user . Is there anyway to add variables for "reply-to" field?
Thank You.
Left by Vish on Jun 24, 2015 11:57 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
I am getting an alert box saying "404:Page not found " on using the functionality.
Left by Naivedya on Jul 03, 2015 11:45 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Vish,
I don't think that is possible. Check out the reference here:

https://msdn.microsoft.com/en-us/library/office/jj246895.aspx#constructors

reply-to is not on the properties list.

This is a very basic feature for the basic email needs. If you need more advanced stuff, you are probably looking at a third party or building an email sending service yourself.

-Thorvald
Left by Thorvald on Jul 07, 2015 12:33 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Naivedya,

Can you tell me more about your environment? If it is OnPremise, it is still possible to use this technique, but it requires some setup. You might get a 404 if you have not set up SMTP in global admin, but I am not sure.

In SharePoint Online, this should work out of the box, but there might be scenarios where it doesnt. You don't give me much to go on, so it is a hard guess :)
Left by Thorvald on Jul 07, 2015 12:38 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
I have a status tracker which has resource name, task name and status. I am looking for an email notification from sharepoint which contains the list items that are created and modified "today" in a table format which should be triggered to a set of users exactly 7pm (it can be the server timings, not specific to any time zonoe) .

Resource name Task name Status
r1 t1 s1
r2 t2 s2

Is there any possiblity that we can do it without having SMTP/ any changes in SharePoint ?

Thanks a ton in advance!
Left by Vignesh Kumar on Jul 14, 2015 12:21 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
this is sharepoint 2010 by the way
Left by Vignesh Kumar on Jul 14, 2015 12:23 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Vignesh,
My first thought is to simply use the alert function on the list. When you add an alert, you can specify a daily summary on all items added or changed to be sent to you at 7.pm every day.

You don't say anything about the recipients of the notifications. if that is you alone, the above solution might work. If you require some logic to who receives the notification based on the contents of the resource list, this solution won't work.

If you need more custom logic, you have several challenges. The first challenge is to trigger the job at 7pm. The second challenge is to determine the recipients. The third is to format your email, and the last one is to send the email.

Since you are working with SP 2010 OnPremise, these challenges can be overcome by either a farm solution or an individual app accessing sharepoint by CSOM.

If you were on SharePoint Online, you would probably have to use the SPO client sdk (CSOM).

A farm solution or individual app would give you the freedom of complete tailor making abilities.

If you are looking for an out of the box solution other than the list alert, the only thing I can think of would be a workflow.You could probably set up a workflow to pause until 7pm, do the job and then go back to the first step again. This solution would be restricted to internal sharepoint recipients.

Good luck!

-Thorvald

Left by Thorvald on Jul 17, 2015 11:09 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
its working for me on SharePoint online, but not working on On Premise.
Left by akki on Jul 23, 2015 1:51 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
What about multiple recipients? How is the to string formatted?
I have tried various separators without success. Works fine using a single recipient.

Left by Bruce Wolfe on Aug 07, 2015 9:04 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
akki,
did you set up the SMTP settings in your On Premise environment?

regards, Thorvald
Left by Thorvald on Sep 01, 2015 11:47 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Bruce,
I don't remember if I tried that. But apparently you can by using comma according to this post:

http://sharepoint.stackexchange.com/questions/110278/sputility-send-email-for-mulitple-users

-Thorvald
Left by Thorvald on Sep 01, 2015 11:49 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
For more advanced email processing, check out SendGrid.

You could e.g. set up a REST API with a SendEmail method that uses SendGrid, and then deploy it to Azure as a free web app.

Then you can use jQuery/Ajax from SharePoint to call the SendEmail method. This way you can send email to whoever you like.

See my new post on SendGrid here:
http://geekswithblogs.net/ThorvaldBoe/archive/2015/09/09/send-email-using-sendgrid.aspx

-Thorvald
Left by Thorvald on Sep 09, 2015 11:03 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hello ,

I am getting the following security error . Can anyone tell me what should I need to do for these ?

Thanks
Ravi k
stacktrace= at Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex)
at Microsoft.SharePoint.SPSecurableObject.CheckPermissions(SPBasePermissions permissionMask)
at Microsoft.SharePoint.Utilities.SPUtility.SendEmail_Client(EmailProperties properties)
at Microsoft.SharePoint.ServerStub.Utilities.SPUtilityServerStub.InvokeStaticMethod(String methodName, ClientValueCollection xmlargs, ProxyContext proxyContext, Boolean& isVoid)
at Microsoft.SharePoint.Client.ServerStub.InvokeStaticMethodWithMonitoredScope(String methodName, ClientValueCollection args, ProxyContext proxyContext, Boolean& isVoid)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPathRoot(Boolean mainRequestPath, EdmParserNode node, Boolean resourceEndpoint, MethodInformation& methodInfo)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPath(Boolean mainRequestPath, String path, String pathForErrorMessage)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.Process()
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.ProcessRequest()
at Microsoft.SharePoint.Client.Rest.RestService.ProcessQuery(Stream inputStream, IList`1 pendingDisposableContainer)
Left by Ravi on Sep 18, 2015 12:47 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Ravi,
you don't say much about what you are trying to do. Is your environment SP 2013 OnPremise? Are you trying to send email to a group?

If so, this might help:
https://support.microsoft.com/en-us/kb/2839070

Otherwise, please tell me more about your environment and what you are trying to do.

Best regards,
Thorvald
Left by Thorvald on Sep 18, 2015 1:21 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Yes i am Using SharePoint 2013 and trying to send for individual mail id's .

Thx
Ravik
Left by Ravi k on Sep 18, 2015 2:01 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
function sendEmail(from, to, body, subject) {

var siteurl = _spPageContextInfo.webAbsoluteUrl;

var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail";
debugger;

$.ajax({
contentType: 'application/json',
url: urlTemplate,
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': { 'type': 'SP.Utilities.EmailProperties' },
'From': from,
'To': { 'results': [to] },
'Body': body,
'Subject': subject
}
}
),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
alert("Email sent");
},
error: function (err) {
console.log(err)
alert(err.responseText);
}
});
}
Left by Ravik on Sep 18, 2015 2:05 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hello ,

I am facing the following error .


{"error":{"code":"-1, System.InvalidOperationException","message":{"lang":"en-US","value":"A recipient must be specified."},"innererror":{"message":"A recipient must be specified.","type":"System.InvalidOperationException","stacktrace":" at System.Net.Mail.SmtpClient.Send(MailMessage message)\r\n at Microsoft.SharePoint.Utilities.SPUtility.SendEmail_Client(EmailProperties properties)\r\n at Microsoft.SharePoint.ServerStub.Utilities.SPUtilityServerStub.InvokeStaticMethod(String methodName, ClientValueCollection xmlargs, ProxyContext proxyContext, Boolean& isVoid)\r\n at Microsoft.SharePoint.Client.ServerStub.InvokeStaticMethodWithMonitoredScope(String methodName, ClientValueCollection args, ProxyContext proxyContext, Boolean& isVoid)\r\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPathRoot(Boolean mainRequestPath, EdmParserNode node, Boolean resourceEndpoint, MethodInformation& methodInfo)\r\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPath(Boolean mainRequestPath, String path, String pathForErrorMessage)\r\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.Process()\r\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.ProcessRequest()\r\n at Microsoft.SharePoint.Client.Rest.RestService.ProcessQuery(Stream inputStream, IList`1 pendingDisposableContainer)"}}}
Left by Ravik on Sep 18, 2015 2:52 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi,

I'm gorwing in my development abilities... may I ask how this is implemented in SPO? Is the function added to a SPD workflow or using Visual studio?


Thanks
Left by M1 on Sep 25, 2015 4:28 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Nevermind... I got it working with SP Designer.

Thanks!
Left by M1 on Sep 25, 2015 5:32 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Please help me to use this code
I just need to copy paste it and change the value and then call this function on a button click?

Thanks
Paru
Left by Paru on Sep 28, 2015 3:07 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Paru,

that is correct. You will also need to add a reference to jQuery. There are different ways to do that, but if you are working only in SharePoint (no SharePoint app/add-in), one easy way is to create an html file, add the jquery reference, then add a script tag with the code above. Save this file to e.g. the site assets library. Then you add a CEWP (Content Editor Web Part) to the page from which you will use the code. The html file could also include the button that triggers the email.

Good luck!
Left by Thorvald on Sep 30, 2015 3:36 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Ravik,

Your error message says: A recipient must be specified.
So the obvious question is, did you specify a recipient..? :-)
As for a more serious answer, I found this article:

https://social.msdn.microsoft.com/Forums/sharepoint/en-US/bb0a16d8-a25c-483a-9061-cb0acfc3a96f/send-email-in-sharepoint-2013-with-apisputilitiesutilitysendemail?forum=appsforsharepoint

Apparently the recipient should be enclosed in quotes. I don't remember what I did, but you could try adding quotes to the recipient as suggested to see if that helps.
Left by Thorvald on Sep 30, 2015 3:48 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
May I ask if you're aware of a reply-to property for the SP.Utilities.EmailProperties class?

At the moment, when users attempt to reply to any such email, it uses the standard no-reply@sharepoint mailbox.
Left by M1 on Oct 01, 2015 4:35 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Nevermind... I just noticed your reply to Vish
Left by M1 on Oct 01, 2015 5:14 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hello ,

Thanks for your reply however i am facing with the following error now .

---------------------------------------------



System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.Utilities.SPUtility.SendEmail_Client(EmailProperties properties) at Microsoft.SharePoint.ServerStub.Utilities.SPUtilityServerStub.InvokeStaticMethod(String methodName, ClientValueCollection xmlargs, ProxyContext proxyContext, Boolean& isVoid) at Microsoft.SharePoint.Client.ServerStub.InvokeStaticMethodWithMonitoredScope(String methodName, ClientValueCollection args, ProxyContext proxyContext, Boolean& isVoid) 71994f9d-f63b-f0c5-1c2e-0d1daedee818

------------------

Would be great if someone can help me asap .

Thanks
Ravi k
Left by Ravi K on Dec 28, 2015 11:50 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hello ,

Now i could able to send mail but it is asking for authorization popup for first time ... Any idea ??

Thanks
Ravi k
Left by Ravi K on Dec 29, 2015 11:31 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi Ravi k,
It is good that you are making progress. May I ask you what system you are using? (SP version, online/onprem)

I am not sure what is causing the authentication request. Does it happen on the ajax request? It could be an idea to check the form digest.

Also check out my other post:
http://geekswithblogs.net/ThorvaldBoe/archive/2015/09/09/send-email-using-sendgrid.aspx

This can be useful if you need more advanced functionality (external recipients, html body, attachments etc.)

regards,
Thorvald
Left by Thorvald on Jan 08, 2016 12:43 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hello ,

Thanks for you help and how ever it is onprem share point 2013 server . Looks like on ajax post it is prompting for login and password .

Thanks
Ravi k
Left by Ravi Kuppala on Jan 18, 2016 7:21 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hello Thorvald ,

It is urgent for me and here is my code .. and it is running sharepoint 2013 onprem server . It is always prompting login screen .. is there any authorization we need to pass ?

----------------------------------
function sendEmail_Latest(from, to, body, subject) {

var siteurl = _spPageContextInfo.webAbsoluteUrl;

var urlTemplate = siteurl + "/_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] },
'Body': body,
'Subject': subject
}
}
),
headers: {

"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),

},
success: function (data) {
alert('Email sent');
},
error: function (err) {
error: errorHandler
}
});
}
Left by Ravi Kuppala on Jan 18, 2016 12:38 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi Ravi,
The first thing you should do is to do a fiddler trace. In particular check for 302 redirects. This could indicate a known problem between sp and .net, see this article:
https://support.microsoft.com/en-us/kb/3062825

Also check IIS and SP logs to find hints about what is causing the problem.

Did you also check the form digest? If that is somehow corrupted, an authentication request seems likely.
-Thorvald
Left by Thorvald on Jan 18, 2016 11:19 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi Thorvald ,
Thanks for your help and we are not getting any errors . It is asking /prompting for login and password for each time we call these java script function .

is it something we need authentication info need to be passed with header ?

Thanks
Ravi k
Left by Ravi Kuppala on Jan 19, 2016 1:43 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi Ravi,
please do a fiddler trace, as this might give you a hint of what is wrong. Especially look for a 302 redirection. This is not an error, but a redirection code. If you get this code, you might need to take steps mentioned in the article.

The only form of authentication you need to make the request is the request digest. Please check that the request digest has a value (it should be a string of random characters).

That is where I would start, along with checking available logs. You need to dig into the problem and find clues as to where to dig further.

Good luck!

-Thorvald
Left by Thorvald on Jan 19, 2016 9:55 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi ,
Please help
When i used this code i am getting error like this
{"error":{"code":"-2130242040, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The e-mail message cannot be sent. Make sure the e-mail has a valid recipient."}}}

I used email as like this i replaced from and To with emails that is correct or not.
'From': xyz@xyz.com,
'To': { 'results': ['xyz@xyz.com'] },



Left by Bharath on Feb 08, 2016 12:13 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi Barath,
the recipient must be a valid SharePoint user. Are you trying to send email outside your organization?

best regards,
Thorvald
Left by Thorvald on Feb 10, 2016 3:46 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi Thorvald,

Thanks for reply

Nope I gave my email who is sitecollection admin. It is inside company only. Not outside. Dont know why still I am getting that error.

Please help
Left by Bharath on Feb 12, 2016 12:36 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Bharath,
I assume you are working on SP 2013 OnPrem?
please check the following:
1.That the recipient actually has an email address on his SharePoint profile
2.That the recipient is on the same domain as the SP server
3.That the recipient has actually logged in to the site from where you are sending the email
4.that you have quotes around the sender email address
5.That your SMTP is setup correctly - you can check this by sending an email e.g. by setting up an alert on a list

regards,
Thorvald
Left by Thorvald on Feb 12, 2016 12:49 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi Thorvald,

I'm developing a SP hosted app in JS & jQuery and can send mail from SP online using this method, but also have the requirement to send Outlook meeting requests.

Any ideas?

Thanks
Johan
Left by Johan on Apr 24, 2016 6:47 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi Johan,
I have no experience on that particular challenge, but my first thought would be to check out the graph api. When logged in to SP online, I suppose you would already be authenticated towards the api, or possibly able to retrieve the bearer token for authentication. Then you can use the api for creating and sending meeting requests. See dev.office.com for more info.

You did not mention if you are online or on premise, but I am assuming online. If you are on premise, it's another game. Then you are probably looking at some proprietary solution.
Good luck!
-Thorvald
Left by Thorvald on Apr 26, 2016 9:58 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Visit the below URL for Rest operations like GET and POST
https://abhisheksahayblog.wordpress.com/
Left by abhishek on May 18, 2016 2:06 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi,

I have valid user but it gives principal null.

Thanks,
Rohidas
Left by Rohidas on May 20, 2016 5:18 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
hi i used sendEmail with workflow on sharepoint designer and valid user on sharepoint site but responscode return Not Found
Left by DG on May 22, 2016 2:29 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi Rohidas,
are you Online or OnPrem?
If OnPrem, you need to setup SMTP settings in central admin. If you have a valid user as a recipient, check if it is a problem only with this user, or all users.
-Thorvald
Left by Thorvald on Jun 09, 2016 11:32 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Hi DG,
see previous answer, same questions go for you.
-Thorvald
Left by Thorvald on Jun 09, 2016 11:34 AM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Thank you so much for the code! It is working well but just wondering how you can send email to multiple recipients. Can you please let me know how?
Left by Jay on Aug 04, 2016 9:22 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Nice blog It is very helpful

But how to send mail to those which are not participant or not shared site to that user...

Left by Sunil on Jan 11, 2017 12:31 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
Sorry for late reply, I don't really follow up this blog anymore.
In Office 365 you can only send email to internal users.
However, you can send external emails using Microsoft Flow. This cannot be done directly with jQuery, but you could add an intermediary step of using jQuery to add a record to a list containing the recipient(s), and have an email flow that triggers on that list and sends email to the described recipients.
-T
Left by Thorvald on Jan 14, 2017 6:07 PM

# re: Sending email with SharePoint and jQuery
Requesting Gravatar...
About multiple recipients, I am not sure whether this is possible as described in the article. It seems the 'to' parameter is utilized as an array, so you could play around with supplying an array to the function and then supplying this array directly in the post, something like this:

$.ajax({
contentType: 'application/json',
url: urlTemplate,
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': { 'type': 'SP.Utilities.EmailProperties' },
'From': from,
'To': { 'results': to }, //'to' is an array of strings
'Body': body,
'Subject': subject
}
}
),

If this doesn't work, you could use a flow as described in the previous comment.

As a more customized approach, you could also use something like SendGrid to send emails, which would allow much more flexibility and none of the limitations in the other solutions. This would require building a separate service (server based) for sending the emails, it could e.g. listen to a SharePoint list every 10. minutes and send emails based on the records added to that list.
Left by Thorvald on Jan 14, 2017 6:16 PM

Your comment:
 (will show your gravatar)


Copyright © Thorvald Bøe | Powered by: GeeksWithBlogs.net