码奴夫人 2014-03-06 11:52 采纳率: 0%
浏览 1311

javamail api接收文件main方法可以,部署到tomcat后,异常

自己写了javamail的收邮件程序,且通过收邮件类的main方法测试成功,能收到所有邮件,但是将此类加入到web应用中后,部署到tomcat,然后通过页面请求后,也能获得message的条数,但是在转化成Part后,就java.lang.NullPointerException,异常了。
Properties props = System.getProperties();

props.put("mail.store.protocol","imap");
props.put("mail.imap.host","imap.163.com");
props.put("mail.imap.auth.plain.disable","true");
try {
Session mailsession=Session.getInstance(props,null);
mailsession.setDebug(false); //是否启用debug模式
IMAPFolder folder= null;
IMAPStore store=null;
store=(IMAPStore)mailsession.getStore("imap"); // 使用imap会话机制,连接服务器
store.connect("mail.163.com","azc118116@163.com","azc1181161");
folder=(IMAPFolder)store.getFolder("INBOX"); //收件箱

folder.open(Folder.READ_WRITE);

Message message[] = folder.getMessages();
int unreadcount=folder.getUnreadMessageCount();
int newmailcount=folder.getNewMessageCount();
int total=folder.getMessageCount();
int p=0;
MailRecive pmm = null;

for(int i=0;i<total;i++)
{
pmm = new MailRecive((MimeMessage) message[i]);

// 获得邮件内容===============

pmm.getMailContent((Part) message[i]);

pmm.setAttachPath("d:/bossinmail");

pmm.saveAttachMent((Part) message[i]);

}
以上代码在类的main函数中独立运行无问题,但是部署到tomcat后,就在 pmm.getMailContent((Part) message[i]); 这句话报空指针异常了。请各位大侠帮忙解决!~谢谢
详细代码请参考
https://code.csdn.net/snippets/221501
https://code.csdn.net/snippets/221516
备注:web框架使用的是struts2

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 fluent的在模拟压强时使用希望得到一些建议
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退