mailservlet.java
Session session = null;
try {
Context initCtx = new InitialContext();
session = (Session) initCtx.lookup("java:comp/env/mail/Session");
} catch (Exception ex) {
System.out.println("lookup error");
System.out.println(ex.getMessage());
ex.printStackTrace();
}
web inf/web.xml
<web-app>
<resource-ref>
<description>mail Session</description>
<res-ref-name>mail/Session</res-ref-name>
<res-type>jakarta.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
......
</web-app>
meta inf/context.xml
<Context>
<Resource name="mail/Session" auth="Container" type="jakarta.mail.Session"
mail.transport.protocol="smtp"
mail.smtp.auth="true"
mail.smtp.host="smtp.gmail.com"
mail.smtp.port="465"
mail.smtp.user="xxxxxxx"
password="xxxxxxxx"
mail.from="xxxxxxx@gmail.com"
mail.smtp.quitwait="false"
mail.smtp.starttls.enable="true"
mail.smtp.socketFactory.class="jakarta.net.ssl.SSLSocketFactory"
mail.debug="true"/>
</Context>
错误:com.sun.mail.util.mailconnectexception:无法连接到主机,端口:localhost,25;超时-1;
我试图做的是通过tomcat创建一个邮件会话示例,并从这个mailid发送电子邮件。我搜索了很多tomcat的how to's。http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#javamail_sessions. 但我找不到导致这种情况的错误。
暂无答案!
目前还没有任何答案,快来回答吧!