1 32 33 package scioworks.imap.presentation.security; 34 35 import java.util.Properties ; 36 37 import javax.mail.*; 38 import javax.mail.internet.*; 39 import javax.activation.*; 40 41 import scioworks.imap.spec.ImapWebConstant; 42 import scioworks.imap.presentation.ImapWebSessionData; 43 44 public class DefaultEmailLogin { 45 46 String username; 47 String password; 48 49 ImapWebSessionData sessionData; 50 51 public DefaultEmailLogin(String username, String password) { 52 this.username = username; 53 this.password = password; 54 } 55 56 public void login() throws ACLException { 57 58 Store store = null; 60 61 Properties props = System.getProperties(); 63 props.put("mail.smtp.host", ImapWebConstant.singleton().smtpHost()); 65 66 Session session = Session.getDefaultInstance(props, null); 68 69 72 try { 73 store = session.getStore("imap"); 74 75 } catch (NoSuchProviderException e) { 76 throw new ACLException("Error getting IMAP provider.", e); 77 } 78 79 try { 80 store.connect(ImapWebConstant.singleton().imapHost(), 81 ImapWebConstant.singleton().imapPort(), 82 username, password); 83 84 } catch (MessagingException e) { 85 86 throw new ACLException("Error connection to email server.", e); 87 88 } 89 90 92 URLName url = new URLName("imap", 94 ImapWebConstant.singleton().imapHost(), 95 ImapWebConstant.singleton().imapPort(), 96 "INBOX", 97 username, 98 password); 99 100 104 sessionData = new ImapWebSessionData(); 105 sessionData.setImapURL (url); 106 sessionData.setImapSession(session); 107 sessionData.setImapStore (store); 108 114 } 115 116 public ImapWebSessionData getSessionData() { 117 return sessionData; 118 } 119 } 120 | Popular Tags |