问题
I have several days trying to get the contents of a message through IMAP on a Google App Engine Project.
I managed to extract all the other information, but to extract the contents of jumps me an error message (not work even invoking message.getContent.tostring(), I've tried as MultiPart).
I perform the same action from a normal project , (not GAE and using javamail.1.4.7), the content of the messages shown perfectly.
This is the code of GAE project:
import java.util.Properties;
import java.util.logging.Logger;
import javax.mail.Session;
import java.io.IOException;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Store;
import javax.servlet.http.*;
@SuppressWarnings("serial")
public class nuevo extends HttpServlet {
private String User;
private String Pass;
private static final Logger log = Logger.getLogger(nuevo.class
.getName());
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
User = "User";
Pass = "Pass";
LlamaIMAP(resp);
}
public void LlamaIMAP(HttpServletResponse resp) {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
props.put("mail.imap.host", "imap.gmail.com");
props.put("mail.imap.user", User);
props.put("mail.imap.socketFactory", 993);
props.put("mail.imap.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.imap.port", 993);
Session session = Session.getDefaultInstance(props,
new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(User, Pass);
}
});
try {
Store store = session.getStore("imap");
store.connect("imap.gmail.com", 993, User, Pass);
Folder fldr = store.getFolder("Inbox");
fldr.open(Folder.HOLDS_MESSAGES);
// HOLDS_MESSAGES);
Message[] ar = fldr.getMessages();
int count = fldr.getMessageCount();
resp.getWriter().println(count);
resp.getWriter().println(ar[0].getAllRecipients()[0].toString());
resp.getWriter().println(ar[0].getFrom()[0].toString());
resp.getWriter().println(ar[0].getSentDate().toString());
resp.getWriter().println(ar[0].getSubject());
resp.getWriter().println(ar[0].getContent().toString());
} catch (Exception exc) {
try {
resp.getWriter().println(exc + "error");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
回答1:
I managed to fix it.
Only you need to add this lines to the appengine-web.xml configuration file:
<class-loader-config>
<priority-specifier filename="imap.jar"/>
<priority-specifier filename="gimap.jar"/>
<priority-specifier filename="dsn.jar"/>
<priority-specifier filename="mailapi.jar"/>
</class-loader-config>
Thanks.
来源:https://stackoverflow.com/questions/17788697/google-app-engine-gae-message-getcontent-using-javamail-and-imap-not-works