我在一个名为 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>
[....]
该代码基于此处显示的第二个通过 JavaMail 发送到 gmail 时出现的 TLS 问题,但尽管据说可以工作,但我无法让它工作。我还测试了输入 root 作为用户和密码并传递用户和密码,如图所示,但它不起作用。
但它似乎没有发送任何东西,也许是接收收件箱无法收到消息但我怀疑它。
知道我做错了什么吗?我已经尝试检查该代码以及更多代码,但它们似乎都不起作用,我不知道为什么,看起来一切正常。
当然,页面的编译非常顺利。
谢谢你的帮助。