Search in sources :

Example 6 with NoSuchProviderException

use of javax.mail.NoSuchProviderException in project selenium-tests by Wikia.

the class EmailUtils method deleteAllEmails.

public static void deleteAllEmails(String userName, String password) {
    try {
        // establishing connections
        Properties props = System.getProperties();
        props.setProperty("mail.store.protocol", "imaps");
        Session session = Session.getDefaultInstance(props, null);
        session.setDebug(false);
        Store store = session.getStore("imaps");
        store.connect("imap.googlemail.com", userName, password);
        // getInbox
        Folder inbox = store.getFolder("Inbox");
        inbox.open(Folder.READ_WRITE);
        Message[] messages = inbox.getMessages();
        if (messages.length != 0) {
            for (int i = 0; i < messages.length; i++) {
                messages[i].setFlag(Flags.Flag.DELETED, true);
            }
        } else {
            PageObjectLogging.log("Mail", "There are no messages in inbox", true);
        }
        store.close();
    } catch (NoSuchProviderException e) {
        PageObjectLogging.log("Mail", e, false);
    } catch (MessagingException e) {
        PageObjectLogging.log("Mail", e, false);
    }
}
Also used : Message(javax.mail.Message) MessagingException(javax.mail.MessagingException) Store(javax.mail.Store) Properties(java.util.Properties) Folder(javax.mail.Folder) NoSuchProviderException(javax.mail.NoSuchProviderException) Session(javax.mail.Session)

Example 7 with NoSuchProviderException

use of javax.mail.NoSuchProviderException in project selenium-tests by Wikia.

the class EmailUtils method getFirstEmailContent.

public static String getFirstEmailContent(String userName, String password, String subject) {
    try {
        PageObjectLogging.logInfo("Checking emails for " + userName + " that contain '" + subject + "'");
        // establishing connections
        Properties props = System.getProperties();
        props.setProperty("mail.store.protocol", "imaps");
        Session session = Session.getDefaultInstance(props, null);
        Store store = session.getStore("imaps");
        store.connect("imap.googlemail.com", userName, password);
        // getInbox
        Folder inbox = store.getFolder("Inbox");
        inbox.open(Folder.READ_ONLY);
        Message[] messages = null;
        boolean forgottenPasswordMessageFound = false;
        Message magicMessage = null;
        for (int i = 0; !forgottenPasswordMessageFound; i++) {
            messages = inbox.getMessages();
            PageObjectLogging.log("Mail", "Waiting for the message", true);
            Thread.sleep(2000);
            for (Message message : messages) {
                if (message.getSubject().contains(subject)) {
                    forgottenPasswordMessageFound = true;
                    magicMessage = message;
                }
            }
            if (i > 15) {
                throw new WebDriverException("Mail timeout exceeded");
            }
        }
        PageObjectLogging.log("Mail", "Mail arrived", true);
        Message m = magicMessage;
        String line;
        StringBuilder builder = new StringBuilder();
        InputStreamReader in = new InputStreamReader(m.getInputStream());
        BufferedReader reader = new BufferedReader(in);
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        store.close();
        return builder.toString();
    } catch (NoSuchProviderException e) {
        PageObjectLogging.log("getFirstEmailContent", e, false);
        throw new WebDriverException();
    } catch (MessagingException | IOException | InterruptedException e) {
        PageObjectLogging.log("getFirstEmailContent", e, false);
        throw new WebDriverException();
    }
}
Also used : Message(javax.mail.Message) InputStreamReader(java.io.InputStreamReader) MessagingException(javax.mail.MessagingException) Store(javax.mail.Store) IOException(java.io.IOException) Properties(java.util.Properties) Folder(javax.mail.Folder) BufferedReader(java.io.BufferedReader) NoSuchProviderException(javax.mail.NoSuchProviderException) Session(javax.mail.Session) WebDriverException(org.openqa.selenium.WebDriverException)

Example 8 with NoSuchProviderException

use of javax.mail.NoSuchProviderException in project Activiti by Activiti.

the class JndiEmailTest method setUp.

@BeforeClass
public void setUp() {
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.provider.class", MockEmailTransport.class.getName());
    props.put("mail.smtp.class", MockEmailTransport.class.getName());
    props.put("mail.smtp.provider.vendor", "test");
    props.put("mail.smtp.provider.version", "0.0.0");
    Provider provider = new Provider(Type.TRANSPORT, "smtp", MockEmailTransport.class.getName(), "test", "1.0");
    Session mailSession = Session.getDefaultInstance(props);
    SimpleNamingContextBuilder builder = null;
    try {
        mailSession.setProvider(provider);
        builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
        builder.bind("java:comp/env/Session", mailSession);
    } catch (NamingException e) {
        logger.error("Naming error in email setup", e);
    } catch (NoSuchProviderException e) {
        logger.error("provider error in email setup", e);
    }
}
Also used : SimpleNamingContextBuilder(org.springframework.mock.jndi.SimpleNamingContextBuilder) NamingException(javax.naming.NamingException) Properties(java.util.Properties) NoSuchProviderException(javax.mail.NoSuchProviderException) Provider(javax.mail.Provider) Session(javax.mail.Session) BeforeClass(org.junit.BeforeClass)

Example 9 with NoSuchProviderException

use of javax.mail.NoSuchProviderException in project ats-framework by Axway.

the class MailSender method initSession.

/**
     * Initialize the SMTP session
     *
     * @throws ActionException
     */
private void initSession() throws ActionException {
    // initialize the mail session with the current properties
    session = Session.getInstance(mailProperties);
    // user can get more debug info with the session's debug mode
    session.setDebug(configurator.getMailSessionDebugMode());
    // initialize the SMPT transport
    try {
        transport = session.getTransport("smtp");
    } catch (NoSuchProviderException e) {
        throw new ActionException(e);
    }
}
Also used : ActionException(com.axway.ats.action.model.ActionException) NoSuchProviderException(javax.mail.NoSuchProviderException)

Example 10 with NoSuchProviderException

use of javax.mail.NoSuchProviderException in project Gargoyle by callakrsos.

the class MailPopReceiver method receiveEmail.

public void receiveEmail() {
    try {
        //1) get the session object  
        //new Properties();
        Properties properties = System.getProperties();
        properties.put("mail.pop3.host", popHost);
        properties.put("mail.user", userName);
        properties.put("mail.from", hostEmailAddr);
        properties.put("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        properties.put("mail.pop3.socketFactory.port", "995");
        properties.put("mail.pop3.port", "995");
        properties.setProperty("mail.pop3.socketFactory.fallback", "false");
        if (this.proxy != null) {
            String hostName = proxy.getHostName();
            int port = proxy.getPort();
            String value = port + "";
            properties.put("proxySet", "true");
            properties.put("socksProxyHost", hostName);
            properties.put("socksProxyPort", value);
            properties.put("http.proxyHost", hostName);
            properties.put("http.proxyPort", port + "");
            properties.put("https.proxyHost", hostName);
            properties.put("https.proxyPort", port + "");
            //#####################################
            properties.setProperty("proxySet", "true");
            properties.setProperty("socksProxyHost", hostName);
            properties.setProperty("socksProxyPort", port + "");
            properties.setProperty("http.proxyHost", hostName);
            properties.setProperty("http.proxyPort", port + "");
            properties.setProperty("https.proxyHost", hostName);
            properties.setProperty("https.proxyPort", port + "");
        }
        Authenticator authenticator = new Authenticator() {

            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(hostEmailAddr, password);
            }
        };
        Session emailSession = Session.getInstance(properties, authenticator);
        //			Session emailSession = Session.getDefaultInstance(properties);
        emailSession.setDebug(debug);
        //2) create the POP3 store object and connect with the pop server  
        //			POP3Store emailStore = (POP3Store) emailSession.getStore(type);
        URLName url = new URLName(type, popHost, 995, "", hostEmailAddr, password);
        POP3SSLStore emailStore = new POP3SSLStore(emailSession, url);
        System.out.println(emailStore.isSSL());
        emailStore.connect();
        System.out.println("connected.");
        //3) create the folder object and open it  
        Folder emailFolder = emailStore.getFolder("INBOX");
        emailFolder.open(Folder.READ_ONLY);
        //4) retrieve the messages from the folder in an array and print it  
        Message[] messages = emailFolder.getMessages();
        for (int i = 0; i < messages.length; i++) {
            Message message = messages[i];
            System.out.println("---------------------------------");
            System.out.println("Email Number " + (i + 1));
            System.out.println("Subject: " + message.getSubject());
            System.out.println("From: " + message.getFrom()[0]);
            System.out.println("Text: " + message.getContent().toString());
        }
        //5) close the store and folder objects  
        emailFolder.close(false);
        emailStore.close();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Message(javax.mail.Message) MessagingException(javax.mail.MessagingException) URLName(javax.mail.URLName) IOException(java.io.IOException) Properties(java.util.Properties) Folder(javax.mail.Folder) POP3SSLStore(com.sun.mail.pop3.POP3SSLStore) NoSuchProviderException(javax.mail.NoSuchProviderException) Authenticator(javax.mail.Authenticator) PasswordAuthentication(javax.mail.PasswordAuthentication) Session(javax.mail.Session)

Aggregations

NoSuchProviderException (javax.mail.NoSuchProviderException)16 Session (javax.mail.Session)10 MessagingException (javax.mail.MessagingException)9 Store (javax.mail.Store)7 Properties (java.util.Properties)6 Folder (javax.mail.Folder)5 Message (javax.mail.Message)5 Transport (javax.mail.Transport)5 UserAuth (org.opennms.netmgt.config.javamail.UserAuth)3 IOException (java.io.IOException)2 ReadmailHost (org.opennms.netmgt.config.javamail.ReadmailHost)2 ActionException (com.axway.ats.action.model.ActionException)1 RbvStorageException (com.axway.ats.rbv.model.RbvStorageException)1 POP3SSLStore (com.sun.mail.pop3.POP3SSLStore)1 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1