电子邮件写信页面开发代码

页面代码

<!DOCTYPE>

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8;application/xml">

        <title>sendMessage</title>

        <script type="text/javascript">

        function addScript(){

            var script = document.createElement('script');

            script.type = 'text/javascript';

            script.src = '../js/packAll.js'

            document.head.appendChild(script);

        }

        </script>

        

    </head>

    <body onload = 'addScript()'>

            <label for = 'sendAddress'>收件人:</label>

            <input type = 'text' name = 'sendAddress' id = 'sendAddress' size = '100'>

            <br>

            <label for = 'emailSubject'>&nbsp;&nbsp;题:</label>

            <input type = 'text' name = 'emailSubject' id = 'emailSubject' size = '100'>

            <br>

            <label for = 'emailContent'>&nbsp;&nbsp;文:</label>

            <textarea style= 'vertical-align: top;' name = 'emailContent' id = 'emailContent' rows = '40' cols = '90' value = '123456'></textarea>

            <br>

            <input type = 'button' id = 'send' value = '发送'>

            

        

    </body>

</html>

js代码

  1     /**

  2             *创建一个Ajax的XHR对象

  3             *@throw 返回一个XHR对象

  4             */

  5              function createXHR() {

  6 

  7                 if (typeof XMLHttpRequest !== "undefined") {

  8                     return new XMLHttpRequest();

  9                 } else if (typeof ActiveXObject !== "undefined") {

 10 

 11                     if (typeof arguments.callee.activeXString !== "string") {

 12                         var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0",

 13                                         "MSXML2.XMLHttp"];

 14                         var i = 0; 

 15                         var len = versions.length;

 16                 

 17                         for (; i < len; i++) {

 18 

 19                             try {

 20                                 new ActiveXObject(versions[i]);

 21                                 arguments.callee.activeXString = versions[i];

 22                                 break;

 23                             } catch (ex){

 24                                 //skip

 25                             }

 26                         }

 27                     }

 28                 

 29                     return new ActiveXObject(arguments.callee.activeXString);

 30                 } else {

 31                     throw new Error("No XHR object available.");

 32                 }

 33             }

 34                /*

 35                *将json格式的对象转化成xml

 36                */

 37             function obj2Xml(obj) {

 38                 

 39                 if (typeof obj !== 'object') {                    

 40                     return ;                

 41                 };

 42                 var result = [];

 43 

 44                 for (var i in obj) {

 45 

 46                     var item = obj[i];

 47                     if (typeof item === 'object') {

 48                         var objStr = arguments.callee(item);

 49                         objStr = '<object name="'+i+'">' + objStr + '</object>'

 50                         result.push(objStr);

 51                     } else {

 52                         var type = typeof item;

 53 

 54                         if (type ==='number') { 

 55                             type = 'int';

 56                         };

 57                         var str = '<'+type+' name=\"'+i+'\">'+item+'</'+type+'>';

 58                         result.push(str);

 59                     }

 60                 }

 61 

 62                 return result.join("\n");

 63             }

 64 

 65 

 66             /**

 67             *跨浏览器监听事件

 68             */

 69             function addHandler(element, type, handler){

 70                 

 71                 if (element.addEventListener){

 72                     element.addEventListener(type, handler, false);

 73                 } else if (element.attachEvent){

 74                     element.attachEvent("on" + type, handler);

 75                 } else {

 76                     element["on" + type] = handler;

 77                 }

 78             }

 79 

 80             function $(selector) {

 81                 return document.getElementById(selector)

 82             }

 83 

 84             var send = $('send');

 85             addHandler(send,'click',function(){

 86                  var sendAddress = $('sendAddress').value;

 87                  var emailSubject = $('emailSubject').value;

 88                  var emailContent = $('emailContent').value;

 89                  var href = location.href;

 90                  var sidIndex = href.indexOf('sid');

 91                  var sid = href.match(/sid=[^&#]+/)[0];

 92                  var rand = Math.floor(Math.random()*1e+14);

 93                  var URL = 'http://appmail.mail.10086.cn/RmWeb/mail?func=mbox:compose&categroyId=103000000&'+sid+'&&comefrom=54&guid='+rand+'&cguid=1614225212258 ';

 94 

 95                 //构建一个邮件对象

 96                 var attrs = {

 97                             account: '[email protected]', 

 98                             to: sendAddress + '',  

 99                             subject: emailSubject + '', 

100                             content: emailContent + '', 

101                             priority: 3,

102                             signatureId: 0, 

103                             saveSentCopy: 1, 

104                             requestReadReceipt: 0, 

105                             inlineResources: 1,

106                             scheduleDate: 0, 

107                             normalizeRfc822: 0

108                         };    

109                 var email = {attrs:attrs, action:'deliver', replyNotify:0, returnInfo:1}

110 

111                 //将email转化成xml

112                 var emailXml = '<object>'+obj2Xml(email)+'</object>';

113                 var sendXhr = createXHR();

114 

115                 sendXhr.onreadystatechange = function(){

116 

117                     if (sendXhr.readyState === 4) {

118                         if ((sendXhr.status >= 200 && sendXhr.status < 300) || sendXhr.status == 304) {

119                                 alert('发送成功');

120                             } else {

121                                 alert('发送失败');

122                             }

123                         };

124                 }

125                 sendXhr.open("POST",URL,true);

126                 sendXhr.send(emailXml);

127 

128                

129             });

你可能感兴趣的:(邮件)