【发布时间】:2013-09-03 01:14:03
【问题描述】:
我在一个名为 clave.jsp 的文件中有以下代码:
@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.detelexia.bbdd.Datos" %>
<%@ page import="com.detelexia.web.Utils" %>
<%@ page import = "java.text.*" %>
<%@ page import="java.io.*,java.util.*,javax.mail.*, javax.mail.Service"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
[....]
<div><a href="javascript:void();" onclick="email(); return false;" class="button button-alt">ENVIAR</a></div>
<script>
function email()
{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.from","existingdirection@gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("existingdirection@gmail.com", "correctpassword");
}
});
try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,
"existingdirection@gmail.com");
msg.setSubject("JavaMail hello world example");
msg.setSentDate(new Date());
msg.setText("Hello, world!\n");
Transport.send(msg);
} catch (MessagingException mex) {
}
}
</script>
[....]
代码基于此处显示的第二个TLS issue when sending to gmail through JavaMail,但尽管据说可以工作,但我无法让它工作。我还测试了输入 root 作为用户和密码并传递用户和密码,如图所示,但它不起作用。
但是好像没有发什么,可能是收件箱收不到邮件但我怀疑。
知道我做错了什么吗?我已尝试检查该代码以及更多代码,但它们似乎都不起作用,我不知道为什么,看起来一切正常。
当然,页面的编译很顺利。
感谢您的帮助。
【问题讨论】:
-
你好@user2638180你怎么能在客户端javascript函数中使用服务器端jsp代码,也许你应该从基础开始