使用SP.Utilities.Utility.SendEmail发送延迟电子邮件 [英] Send delay email with SP.Utilities.Utility.SendEmail
问题描述
我在JS中有这个功能。我使用的是SharePoint 2013。
我的功能正常但我想发送延迟交付。有人可以帮助我,有些人告诉我在SharePoint中使用WF,但我不想重新启动所有内容。
this 。sendEmail =
功能 (from,to,body,subject ){
       
var deferred = $ q.defer();
  ; 
var siteurl = _spPageContextInfo.webAbsoluteUrl;
var urlTemplate = siteurl +
" / _ API / SP.Utilities.Utility.SendEmail" 跨度> <跨度郎=" EN-CA"style ="background:white; color:black; font-family:Consolas; font-size:9.5pt">;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; $ http({
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; URL:urlTemplate,跨度>
<跨度郎=" EN -CA"style ="background:white; color:black; font-family:Consolas; font-size:9.5pt"> 方法:
" POST" ,
  ; 标题:{
&nb属;&NBSP;&NBSP;&NBSP;&NBSP;
" Accept" :
"应用/ JSON; odata = verbose" ,
&NBSP;&NBSP;&NBSP;&NBSP;
" X-RequestDigest" :$( " #__ REQUESTDIGEST" )。val(),
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
" Content-Type" :
" application / json; odata = verbose"
},
;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;数据:JSON.stringify({
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
跨度> <跨度郎=" EN -CA"style ="background:white; color:#a31515; font-family:Consolas; font-size:9.5pt">'properties' :{
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;
'__元数据' :{
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
'type' :
'SP.Utilities.EmailProperties'
},
'从' :from,
'到' :{
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
'结果' :[to]
},
'Body' :body,
'主题' :subject
}
})
})。then( function
(成功){
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; deferred.resolve(成功); 跨度>
  ; },
function (错误){
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; deferred.reject(跨度> <跨度郎=" EN -CA"style ="background:white; color:#a31515; font-family:Consolas; font-size:9.5pt">'Request
failed。' + error.statusText);
});
返回 deferred.promise;
}
我们可以使用setTimeOut函数延迟sendEmail函数的执行,如下所示:
< script type =" text / javascript" src =" https://code.jquery.com/jquery-1.11.0.min.js">< / script> ;
< script type =" text / javascript">
(document).ready(function(){
setTimeOut(processSendEmails,3000);
});
函数processSendEmails(){
var from ='Administrator@contoso.com',
to ='Administrator@contoso.com',
body ='Hello',
subject ='Hello';
console.log(from);
console.log(to);
console.log(body );
console.log(subject);
sendEmail(from,to,body,subject);
}
函数sendEmail(from,to,body,主题){
//获取网站的相对网址
var siteurl = _spPageContextInfo.webAbsoluteUrl;
var urlTemplate = siteurl +" / _ api / SP.Utilities.Utility.SendEmail" ;;
.ajax({
contentType:'application / json',
url:urlTemplate,
类型:" POST",
data:JSON.stringify({
'properties':{
'__metadata':{
'type':'SP.Utilities.EmailProperties'
},
'从':从,
'到':{
'结果':[到]
},
'正文':正文,
'主题':主题
}
}),
标题:{
"接受" ;:"application / json; odata = verbose",
" content-type":" application / json; odata = verbose",
" X-RequestDigest":jQuery(" #__ REQUESTDIGEST")。val()
},
成功:函数(数据){
alert('电子邮件已成功发送');
},
错误:函数(错误){
alert('发送电子邮件时出错:'+ JSON.stringify(错误));
}
});
}
< / script>
谢谢
最好的问候
Hi, I have this function in JS. I use SharePoint 2013.
My function work fine but I want to send delay delivery with it. Can somebody help me, some people told me to use WF in SharePoint but I don't want to restart everything.
this.sendEmail = function (from, to, body, subject) {
var deferred = $q.defer();
var siteurl = _spPageContextInfo.webAbsoluteUrl;
var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail";
$http({
url: urlTemplate,
method: "POST",
headers: {
"Accept": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"Content-Type": "application/json;odata=verbose"
},
data: JSON.stringify({
'properties': {
'__metadata': {
'type': 'SP.Utilities.EmailProperties'
},
'From': from,
'To': {
'results': [to]
},
'Body': body,
'Subject': subject
}
})
}).then(function (success) {
deferred.resolve(success);
},
function (error) {
deferred.reject('Request failed. ' + error.statusText);
});
return deferred.promise;
}
Hi,
We can delay the sendEmail function execution with setTimeOut function like below:
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript">
(document).ready(function () { setTimeOut(processSendEmails,3000); }); function processSendEmails() { var from = 'Administrator@contoso.com', to = 'Administrator@contoso.com', body = 'Hello', subject = 'Hello'; console.log(from); console.log(to); console.log(body); console.log(subject); sendEmail(from, to, body, subject); } function sendEmail(from, to, body, subject) { //Get the relative url of the site 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": jQuery("#__REQUESTDIGEST").val() }, success: function(data) { alert('Email Sent Successfully'); }, error: function(err) { alert('Error in sending Email: ' + JSON.stringify(err)); } }); } </script>Thanks
Best Regards
这篇关于使用SP.Utilities.Utility.SendEmail发送延迟电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!