简体   繁体   English

无法通过Java Servlet发送电子邮件

[英]Not able to send email via Java servlet

I am getting this error when trying to send emails via gmail smtp inside servlet it works locally when tested but not inside google engine i added the libs under web-inf/libs [activation.jar-smtp.jar- mailapi.jar - mail.jar] any idea how i can fix it!! 我在尝试通过servlet内部的gmail smtp发送电子邮件时收到此错误,它在经过测试时可以在本地工作,但在Google引擎内部却没有,我在web-inf / libs [activation.jar-smtp.jar- mailapi.jar-邮件下添加了libs。 jar]知道我该如何解决!!

Error: javax.servlet.ServletContext log: unavailable java.lang.SecurityException: SHA1 digest error for javax/mail/Message.class at com.google.appengine.run 错误: javax.servlet.ServletContext log: unavailable java.lang.SecurityException: SHA1 digest error for javax/mail/Message.class at com.google.appengine.run javax.servlet.ServletContext log: unavailable java.lang.SecurityException: SHA1 digest error for javax/mail/Message.class at com.google.appengine.run

Code Snapshot: 代码快照:

 Properties props = new Properties();
 props.setProperty("mail.transport.protocol", "smtp");
 props.setProperty("mail.host", "smtp.gmail.com");
 props.put("mail.smtp.auth", "true"); 
 props.put("mail.smtp.port", "465"); 
 //props.put("mail.debug", "true");
 props.put("mail.smtp.socketFactory.port", "465");
 props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
 props.put("mail.smtp.socketFactory.fallback", "false");
 javax.mail.Session sess = javax.mail.Session.getInstance(props);
 Transport transport = sess.getTransport(); 
 transport.connect();
 transport.send(message);

You cannot use signed jar files on Google app engine. 不能在Google App Engine上使用签名的jar文件。

As indicated on the web page, you should try to unsign it, specifically the mail.jar because the error is indicating javax/mail/Message.class , see this question for an example 如网页上所示,您应该尝试取消签名,特别是mail.jar因为错误指示javax/mail/Message.class ,请参见此问题的示例

App Engine's precompilation isn't compatible with signed JAR files. App Engine的预编译与签名的JAR文件不兼容。 If your application is precompiled (the default), it can't load signed JAR files. 如果您的应用程序是预编译的(默认),则无法加载签名的JAR文件。 If the application tries to load a signed JAR, at runtime App Engine will generate an exception like yours. 如果应用程序尝试加载签名的JAR,则App Engine在运行时会生成与您类似的异常。
No Signed JAR Files 没有签名的JAR文件

There is two way to work around. 有两种解决方法。

  1. Strip the JAR's signature 剥离JAR的签名
  2. Disabling Precompilation 禁用预编译

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM