我有这个错误,我不能修复,我不知道是什么错了。我被困在这里。
这个错误意味着什么?com.google.apphosting.API.apiProxy$呼叫未找到异常:无法进行API调用邮件。请发送一个既不是原始请求线程也不是ThreadManager创建的线程
这是完整的堆栈跟踪:
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at com.wealthsystems.sim3g.modulo.email.impl.EnviaEmailsThread.process(EnviaEmailsThread.java:123)
at com.wealthsystems.dao.hibernate.api.service.WsThreadService.run(WsThreadService.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call mail.Send in a thread that is neither the original request thread nor a thread created by ThreadManager
at com.google.apphosting.api.ApiProxy$CallNotFoundException.foreignThread(ApiProxy.java:800)
at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:112)
at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:65)
at com.google.appengine.api.mail.MailServiceImpl.doSend(MailServiceImpl.java:101)
at com.google.appengine.api.mail.MailServiceImpl.send(MailServiceImpl.java:34)
at com.google.appengine.api.mail.stdimpl.GMTransport.sendMessage(GMTransport.java:223)
at javax.mail.Transport.send(Transport.java:95)
at javax.mail.Transport.send(Transport.java:48)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 10 more
这是我的代码,生成此错误:
public static void sendMailApache(String protocol, String host, String port, String userName, String password,
String subject, byte[] content, String para, String cc, String co) {
try {
final Email email = new SimpleEmail();
email.setHostName(host);
email.setSmtpPort(Integer.parseInt(port));
email.setTLS(true);
email.setSSL(false);
email.setAuthenticator(new DefaultAuthenticator(userName, password));
email.setFrom(userName);
email.setSubject(subject);
email.setCharset(org.apache.commons.mail.Email.ISO_8859_1);
for (String str: para.split(";")) {
email.addTo(str);
}
for (String str: cc.split(";")) {
email.addCc(str);
}
for (String str: co.split(";")) {
email.addBcc(str);
}
email.setMsg(content.toString());
email.send();
} catch (EmailException e) {
throw new RuntimeException(e);
}
}
这个错误意味着什么?我做错了什么?
2条答案
按热度按时间inn6fuwd1#
这意味着你不能使用不是由ThreadManager创建的线程。在你的例子中,你试图使用一个
ScheduledThreadPoolExecutor
,默认情况下会使用“非法”线程。您需要从
ThreadManager
(很可能是backgroundThreadFactory()
)提供一个ThreadFactory
,这样创建的线程才是“正确的”线程,GAE不会抱怨。qjp7pelc2#
尝试注解
com.google.appengine
依赖项并重试。希望它能工作。