gpt4 book ai didi

java - 在jsp中使用imap从gmail读取电子邮件

转载 作者:行者123 更新时间:2023-12-01 14:39:39 25 4
gpt4 key购买 nike

我想使用带有 servlet 和 jsp 的 imap 读取来自 gmail 的电子邮件。但我无法做到这一点。我进入了简单的 Java 类。但是当我在 jsp 和 servlet 中尝试这段代码时,都会出现错误。我使用了以下代码。

try{
java.util.Properties properties = System.getProperties();
properties.setProperty("mail.store.protocol", "imaps");
javax.mail.Session s = javax.mail.Session.getDefaultInstance(properties, null);
//create session instance
System.out.println("Connected");
javax.mail.Store store = s.getStore("imaps");//create store instance
store.connect("pop.gmail.com", "studentusecmp@gmail.com", "##########");
//set your user_name and password
System.out.println(store);
Folder inbox = store.getFolder("inbox");
//set folder from where u wants to read mails
inbox.open(Folder.READ_WRITE);//set access type of Inbox
Message messages[] = inbox.getMessages();// gets inbox messages
for (int i = 0; i System.out.println("From : " + messages[i].getFrom()[0]); //print email id of sender System.out.println("Sub : " + messages[i].getSubject()); //print subject of email
System.out.println("Receive Date:"+messages[i].getReceivedDate());
System.out.println("Description:"+messages[i].getDescription());
}catch(Exception e) { e.printStackTrace(); }

和错误

Stacktrace: at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:97) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:352) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:339) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

我做错了什么?请帮助我。
谢谢。
-金丹

最佳答案

好的。经过一番谷歌搜索后我得到了答案。并一步步检查代码。它在/WebContent/lib/文件夹中找不到 jar 文件。我手动添加的。效果很好。

关于java - 在jsp中使用imap从gmail读取电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16104327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com