I'm having this error and I'm can't fix, I don't know what is wrong. I'm stuck in this.
What this error means? 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
This is the full stacktrace:
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
This is my code that generate this error:
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);
}
}
What this error means? What I'm doing wrong?
It means you can't use an threads that are not created by ThreadManager . In your case you're trying to use a ScheduledThreadPoolExecutor
which by default would use "illegal" threads.
You'll need to supply a ThreadFactory
from the ThreadManager
(most likely the backgroundThreadFactory()
), so the threads created are "proper" threads and GAE doesn't complain.
Try commenting the com.google.appengine
dependency and try again. Hope it works.
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>...</version>
</dependency>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.