ReceiveMail.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:2k
- package com.softeem.webmail.receive;
- import java.io.IOException;
- import java.util.Iterator;
- import java.util.List;
- import javax.mail.Message;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.softeem.webmail.action.receivemail.getReceive;
- import com.softeem.webmail.beans.receive.User;
- import com.softeem.webmail.dao.mail.Mail;
- import com.softeem.webmail.dao.mail.MailDAO;
- import com.softeem.webmail.dao.receive.getUserInfo;
- public class ReceiveMail extends HttpServlet {
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doPost(request, response);
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- User user=(User) request.getSession(false).getAttribute("user");
- String username=user.getUsername();
- User myuser=getUserInfo.getInfo(username);
- String name=username.split("@")[0];
- String host =username.split("@")[1].split("\.")[0];
- System.out.println(host+"主机");
- String password = myuser.getPassword();
- Message[] message =getReceive.getMessage(host,name,password);
- System.out.println(message.length+"邮件数量message");
- List<Mail> mails=getReceive.getMail(message,username,request);
- System.out.println(mails.size()+"邮件数量");
- for(Iterator<Mail> item=mails.iterator();item.hasNext();){
- MailDAO.insertMail(item.next());
- }
-
- response.sendRedirect("ReceiveMailShow");
- }
- }