邮件发送的js和参数的传送

来源:互联网 发布:大数据与医疗 编辑:程序博客网 时间:2024/06/12 10:16

js.page


function goSend() {

    var Inbox = $("#Inbox").val();
    var Outbox = $("#Outbox").val();
    var userName = $("#userName").val();
    var passWord = $("#passWord").val();
    var message = $("#message").val();
    var smtp = $("#smtp").val();
    var Subject = $("#Subject").val();
    $.get("Mail!sendMail.action?Inbox=" + Inbox + "&Outbox=" + Outbox + "&message=" + message + "&userName=" + userName + "&passWord=" + passWord + "&smtp=" + smtp + "&Subject=" + Subject,
    function(data, textStatus) {
        if ("0" == data) {
            alert("发送成功");
            $("#sendEmailDiv").dialog("close");
        } else {
            alert("发送失败");
            $("#sendEmailDiv").dialog("close");
        }

    });

}



vm.page

<form >
     <table class="table_01" cellpadding="0" cellspacing="0" width="500px">
        <tr>
        <td>
            用户名:<input type="text" size="25" id="userName" name="userName"/>
            密 &nbsp;&nbsp;码:<input type="password" id="passWord" name="passWord" size="25"/>
        </td>
        </tr>
        <tr >
            <td align="left">收件人:<input type="text" size="25" id="Inbox" name="Inbox" />
            发件人:<input type="text" size="25" id="Outbox" name="Outbox"/></td>
        </tr>
        <tr>
            <td align="left">主 &nbsp;&nbsp;题:<input type="text"  size="25" id="Subject" name="Subject">
                            选择smtp服务器<select id="smtp" name="smtp" >
                            <option value="smtp.ym.163.com">163企业邮箱邮箱</option>
                            <option value="smtp.qq.com">QQ邮箱</option>
                            <option value="smtp.163.com">163邮箱邮箱</option>
                            <option value="smtp.126.com">126网易邮箱</option>
                            </select>
            </td>
        </tr>
        <tr>
            <td align="left" >内&nbsp;&nbsp;&nbsp;容:<textarea rows="10" cols="60" name="message"  id="message"> </textarea></td>
        </tr>
        
        <tr>
            <td>
                <input type="button" value="发送" id="send" class="Button" onclick="goSend()"/>
                <input type="button" value="取消" id="closeSend" class="Button" onclick="closeMail()"/>
            </td>
        </tr>
     </table>
</form>


action.page


public Object javaMail() throws mException{
        VelocityContext context=new VelocityContext();
        return mSGA.mergeVelocity("JavaKing/javaMail.vm", context);
    }
    
    public int sendMail()throws mException, AddressException, MessagingException
    {
        String userName=request.getParameter("userName");
        String passWord=request.getParameter("passWord");
        String Inbox=request.getParameter("Inbox");
        String Outbox=request.getParameter("Outbox");
        String message=request.getParameter("message");
        String smtp=request.getParameter("smtp");
        String Subject=request.getParameter("Subject");
        return sendForMail(userName,passWord,Inbox,Outbox,message,smtp,Subject);
    }
        /**
         * 一个用户给一个用户发送邮件
         * @param args
         * @throws MessagingException
//         */

    private static int sendForMail(String userName, String passWord, String inbox,String outbox, String message, String smtp, String subject) throws AddressException, MessagingException{
        Properties props=new Properties();
        props.setProperty("mail.smtp.auth","true");//邮箱认证
        props.setProperty("mail.transport.protocol", "smtp");//协议
        Session session=Session.getInstance(props);
        session.setDebug(true);//查看调试信息
        Message msg=new MimeMessage(session);          //消息(卫星)
        msg.setText(message);      //发送的消息的内容,若全为文本则用Test
        msg.setFrom(new InternetAddress(outbox));             //发件人信息
        msg.setSubject(subject);        //标题
        Transport transport=session.getTransport();//火箭
        transport.connect(smtp,25,userName,passWord); //发件人地址账号密码 用户主机 端口
        transport.sendMessage(msg,new Address[]{new InternetAddress(inbox)});//火箭发送卫星 收件人地址 动态方法
        transport.close();
        return 0;
    }
   

对于用velocity,SSI,xml自己所配置sql的情况下所进行的发送,此邮件发送没有用到sql 书写,没有记录发送信息,只有页面和代码之间的交互,运用smtp接口进行发送。