ReceiveMail.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:2k
源码类别:

WEB邮件程序

开发平台:

Java

  1. package com.softeem.webmail.receive;
  2. import java.io.IOException;
  3. import java.util.Iterator;
  4. import java.util.List;
  5. import javax.mail.Message;
  6. import javax.servlet.ServletException;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import com.softeem.webmail.action.receivemail.getReceive;
  11. import com.softeem.webmail.beans.receive.User;
  12. import com.softeem.webmail.dao.mail.Mail;
  13. import com.softeem.webmail.dao.mail.MailDAO;
  14. import com.softeem.webmail.dao.receive.getUserInfo;
  15. public class ReceiveMail extends HttpServlet {
  16. public void doGet(HttpServletRequest request, HttpServletResponse response)
  17. throws ServletException, IOException {
  18. doPost(request, response);
  19. }
  20. public void doPost(HttpServletRequest request, HttpServletResponse response)
  21. throws ServletException, IOException {
  22. User user=(User) request.getSession(false).getAttribute("user");
  23. String username=user.getUsername();
  24. User myuser=getUserInfo.getInfo(username);
  25. String name=username.split("@")[0];
  26. String host =username.split("@")[1].split("\.")[0];
  27. System.out.println(host+"主机");
  28. String password = myuser.getPassword();
  29. Message[] message =getReceive.getMessage(host,name,password);
  30. System.out.println(message.length+"邮件数量message");
  31. List<Mail> mails=getReceive.getMail(message,username,request);
  32. System.out.println(mails.size()+"邮件数量");
  33. for(Iterator<Mail> item=mails.iterator();item.hasNext();){
  34. MailDAO.insertMail(item.next());
  35. }
  36. response.sendRedirect("ReceiveMailShow");
  37. }
  38. }