Rest API发送邮件问题 [英] Rest API send mail issue

查看:202
本文介绍了Rest API发送邮件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用rest API发送邮件。下面是代码。我在Field中指定了电子邮件地址,但在To中指定的用户没有收到邮件,但是CC用户正在接收邮件。

I am sending mail using rest API. Below is the code. I am specifying email address in to Field but user specified in To is not receiving the mail but CC users are receiving the mail.

请记住将回复标记为答案或投票为有帮助的他们帮忙。

Please remember to mark the replies as answers or vote as helpful if they help.

推荐答案

请检查dataJson中的'To'值对象在您身边有效,您可以在Browser Developer Tool中添加一个断点并跟踪该值,确保它是有效的。

Please check if the 'To' value in dataJson object is valid in your side, you could add a break point in Browser Developer Tool and Trace the value, make sure it is valid.

这是一个在我的工作中的代码片段我直接指定了电子邮件地址:

And here is a code snippet which is working in my side, I directly assign the email address:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">


(document).ready(function(){

SP.SOD。 executeFunc('sp.js','SP.ClientContext',processSendEmails);

});

函数processSendEmails(){

var from ='jerry@xxx.onmicrosoft.com',
to ='wendy@xxx.onmicrosoft.com',
cc ='jerry@xxx.onmicrosoft.com'
body ='Hello World Body',
subject ='Hello World Subject';

//调用sendEmail函数
//
sendEmail(from,to,cc,body,subject);
}

函数sendEmail(from,to,cc,body,subject){
//获取网站的相对网址
var siteurl = _spPageContextInfo.webServerRelativeUrl ;
var urlTemplate = siteurl +" / _ api / SP.Utilities.Utility.SendEmail" ;;
(document).ready(function () { SP.SOD.executeFunc('sp.js', 'SP.ClientContext', processSendEmails); }); function processSendEmails() { var from = 'jerry@xxx.onmicrosoft.com', to = 'wendy@xxx.onmicrosoft.com', cc='jerry@xxx.onmicrosoft.com' body = 'Hello World Body', subject = 'Hello World Subject'; // Call sendEmail function // sendEmail(from, to,cc,body, subject); } function sendEmail(from, to,cc, body, subject) { //Get the relative url of the site var siteurl = _spPageContextInfo.webServerRelativeUrl; var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail";


.ajax({
contentType:'application / json',
url:urlTemplate,
类型:" POST",
data:JSON.stringify({
'properties':{
'__metadata':{
'type':'SP.Utilities.EmailProperties'
},
'从':从,
'到':{
'结果':[到]
},
'CC':{
'结果':[cc]
},

'身体':正文,
'主题':主题
}
}),
标题:{
"接受":" application / json; odata = verbose",
"内容-type":" application / json; odata = ver bose",
" X-RequestDigest":jQuery(" #__ REQUESTDIGEST")。val()
},
成功:函数(数据){
alert('电子邮件已成功发送');
},
错误:函数(错误){
alert('发送电子邮件时出错:'+ JSON.stringify(错误));
}
});
}

< / script>
.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] }, '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>






谢谢

最好的问候


这篇关于Rest API发送邮件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆