zoukankan      html  css  js  c++  java
  • SPS中使用JSOM发邮件

    直接上代码了:

            function ShowMailDialog() {
    
                $.ajax({
                    url: siteurl + "/_api/contextinfo",
                    method: "POST",
                    headers: { "Accept": "application/json; odata=verbose" },
                    success: function (data) {
                        alert(data.d.GetContextWebInformation.FormDigestValue);
                        $('#__REQUESTDIGEST').val(data.d.GetContextWebInformation.FormDigestValue)
    
                        var from = 'Yang.Liu4@xxxx.com',
                            to = 'Yang.Liu4@xxxx.com',
                            body = 'Hello World Body',
                            subject = 'Hello World Subject';
    
                        // Call sendEmail function
                        sendEmail(from, to, body, subject);
                    },
                    error: function (data, errorCode, errorMessage) {
                        alert(errorMessage)
                    }
                });
    
                return;
            }
            function sendaEmail(from, to, body, subject) {
                //Get the relative url of the site
                var _ctx = SP.ClientContext.get_current();
                var _spPageContextInfo = _ctx.get_web();
                    //_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": jQuery("#__REQUESTDIGEST").val()
                    },
                    success: function (data) {
                        alert('Email Sent Successfully');
                    },
                    error: function (err) {
                        alert('Error in sending Email: ' + JSON.stringify(err));
                    }
                });
            }
    View Code
  • 相关阅读:
    初识Redis
    一次kafka的offset回退事件及相关知识点
    接口透传
    看懂Oracle执行计划
    Oracle中merge into的使用
    动态规划算法:0/1背包问题 (0/1 Knapsack Problem)
    动态规划算法:硬币找零(Minimum Coin Change)
    链表:按照左右半区的方式重新组合单链表
    链表:删除链表中倒数第K个节点
    链表:合并两个有序链表
  • 原文地址:https://www.cnblogs.com/windy2008/p/5923954.html
Copyright © 2011-2022 走看看