Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从SMTP java类和jsp页面的onclick JavaScript函数发送电子邮件_Javascript_Java_Html_Ajax_Smtp - Fatal编程技术网

从SMTP java类和jsp页面的onclick JavaScript函数发送电子邮件

从SMTP java类和jsp页面的onclick JavaScript函数发送电子邮件,javascript,java,html,ajax,smtp,Javascript,Java,Html,Ajax,Smtp,早上好 我希望有人能帮上大忙:) 我只是想知道如何编写JavaScript:) 我目前有一个文本字段和一个按钮,但我希望该按钮能将消息框信息发送到电子邮件地址onclick,但我不太确定如何执行JavaScript部分,我想知道如何在JS中调用Java类,然后执行onclick函数发送电子邮件 先谢谢你 public class SendMailTLS { public static void main(String[] args) { final String username =

早上好

我希望有人能帮上大忙:)

我只是想知道如何编写JavaScript:)

我目前有一个文本字段和一个按钮,但我希望该按钮能将消息框信息发送到电子邮件地址onclick,但我不太确定如何执行JavaScript部分,我想知道如何在JS中调用Java类,然后执行onclick函数发送电子邮件

先谢谢你

public class SendMailTLS {

public static void main(String[] args) {

    final String username = "diamantengoud@gmail.com";
    final String password = "********";

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    Session session = Session.getInstance(props,
            new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("diamantengoud@gmail.com"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("jp.pretorius@bmgi.co.za"));
        message.setSubject("Testing Subject");
        message.setText("Dear Mail Crawler,"
                + "\n\n No spam to my email, please!");

        Transport.send(message);

        System.out.println("Done");

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }
}


<form  method="post" enctype="text/plain" >
                            <h1>Send a Message</h1>
                            <br>
                            <br>
                            <form class="form-horizontal"  a>
                                <div class="form-group">
                                    <label for="inputName" class="control-label col-xs-2">Name</label>
                                    <div class="col-xs-10">
                                        <input type="" class="form-control" id="inputName" placeholder="">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail" class="control-label col-xs-2">Email</label>
                                    <div class="col-xs-10">
                                        <input type="" class="form-control" id="inputEmail" placeholder="">
                                    </div>
                                </div>
                                <div class="form-group" >
                                    <label for="inputMessage">Message</label>
                                    <textarea  class="form-control"  style="height: 300px" id="inputMessage" rows=""></textarea>
                                </div>
                                <div class="form-group">
                                    <div class="col-xs-offset-2 col-xs-50">
                                        <button onclick="" value="Send" id="send-button" type="submit" class="btn btn-primary">Send</button>
                                    </div>
                                </div>
                            </form>
公共类SendMailTLS{
公共静态void main(字符串[]args){
最终字符串用户名=”diamantengoud@gmail.com";
最终字符串密码=“*******”;
Properties props=新属性();
props.put(“mail.smtp.auth”,“true”);
props.put(“mail.smtp.starttls.enable”、“true”);
put(“mail.smtp.host”、“smtp.gmail.com”);
props.put(“mail.smtp.port”,“587”);
会话=会话.getInstance(props,
新的javax.mail.Authenticator(){
受保护的密码身份验证getPasswordAuthentication(){
返回新密码身份验证(用户名、密码);
}
});
试一试{
Message Message=新的mimessage(会话);
message.setFrom(新的InternetAddress(“diamantengoud@gmail.com"));
message.setRecipients(message.RecipientType.TO,
InternetAddress.parse(“jp。pretorius@bmgi.co.za"));
message.setSubject(“测试主体”);
message.setText(“亲爱的邮件爬虫,”
+“\n\n请不要向我的电子邮件发送垃圾邮件!”);
传输。发送(消息);
系统输出打印项次(“完成”);
}捕获(消息异常e){
抛出新的运行时异常(e);
}
}
发送消息


名称 电子邮件 消息 发送
您可以使用现有的java代码创建一个servlet,并在javascript中进行ajax调用。通过谷歌搜索如何进行ajax调用和创建servlet。请看以下问题: