【问题标题】:sending mail with java sendmail in GWT servlet deployed to tomcat在部署到 tomcat 的 GWT servlet 中使用 java sendmail 发送邮件
【发布时间】:2015-05-12 20:07:45
【问题描述】:

我有一个在 java 1.7 中编译的 eclipse 项目,并在 tomcat 6 中编译。当我使用下面的代码发送电子邮件时,我收到以下错误:

at com.google.appengine.api.mail.stdimpl.GMTransport.sendMessage(GMTransport.java:236)
at javax.

maicom.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'mail' or call 'Send()' was not found.
    at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:109)
    at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:64)
    at com.google.appengine.api.mail.MailServiceImpl.doSend(MailServiceImpl.java:101)
    at com.google.appengine.api.mail.MailServiceImpl.send(MailServiceImpl.java:34)
l.Transport.send(Transport.java:95)
    at javax.mail.Transport.send(Transport.java:48)
...

代码是:

  try {

      Message msg = new MimeMessage(session);

    msg.setFrom(new InternetAddress(from, "hello from admin"));
    msg.addRecipient(Message.RecipientType.TO,
    new InternetAddress(to, “user”));
    msg.setSubject(subject);
    msg.setText(message);


      Transport.send(msg);


  } catch (AddressException e) {
    myPrint("Address exception: "+e);

      // ...
  } catch (MessagingException e) {
    myPrint("Messaging exception: "+e);

      // ...
  }

在创建和部署war文件之前,我已将最新的oracle mail.jar和相关的lib文件夹放入war/WEB-INF/lib目录中。

虽然有一两个类似的关于堆栈溢出的报告,但似乎没有一个可以解决这个问题。

【问题讨论】:

  • 如果将 App Engine 包部署到自己的服务器,为什么还要使用它?
  • Andrei :您指的是哪个特定的包?或者您是否暗示项目设置/配置有问题?

标签: java eclipse email tomcat gwt


【解决方案1】:

已解决

原因:Google 应用引擎已在较早阶段添加到项目中。 Google 应用引擎类隐藏 javax.mail 类,因此源中 javax.mail 类的导入不会在 IDE 中显示为未解析的引用。因此,我不知不觉地使用了应用程序引擎版本进行编译。将应用引擎代码部署到自己的服务器会导致此错误,因为引用了错误的类库。

解决方案

  1. 在不添加 GWT 应用引擎功能的情况下重建项目。
  2. 创建库文件夹,导入你需要的java邮件.jar文件 并添加到构建路径:对于 Eclipse IDE:右键单击文件并 选择添加到构建路径。
  3. 重新编译并部署到自己的服务器。然后代码(如上)将 工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-19
    • 2016-05-31
    • 2014-12-10
    • 1970-01-01
    • 2018-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多