Java TimeUnit Usage getMailServerProps(String toAddress, int smtpPort, int imapPort)

Here you can find the source of getMailServerProps(String toAddress, int smtpPort, int imapPort)

Description

Sets up the properties in order to connect to the green mail test server.

License

Open Source License

Parameter

Parameter Description
toAddress is used for the username and password.
smtpPort for smtps
imapPort for imaps

Return

Properties instance holding appropriate values for java mail.

Declaration

public static Properties getMailServerProps(String toAddress, int smtpPort, int imapPort) 

Method Source Code

//package com.java2s;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

public class Main {
    /**//from ww  w  .  j a  va  2 s .co m
     * Maximum number of messages in a batch.
     */
    protected static final int MAX_NUM_MSGS_IN_BATCH = 5;
    /**
     * Connection Timeout in Milliseconds.
     */
    protected static final String TIMEOUT_CONNECTION_MILLIS = Long.toString(TimeUnit.SECONDS.toMillis(15));
    /**
     * Socket Timeout in Milliseconds.
     */
    protected static final String TIMEOUT_MILLIS = Long.toString(TimeUnit.MINUTES.toMillis(3));

    /**
     * Sets up the properties in order to connect to the green mail test server.
     * 
     * @param toAddress is used for the username and password.
     * @param smtpPort for smtps
     * @param imapPort for imaps
     * @return Properties instance holding appropriate values for java mail.
     */
    public static Properties getMailServerProps(String toAddress, int smtpPort, int imapPort) {

        Properties props = new Properties();

        props.setProperty("connect.mail.user", toAddress);
        props.setProperty("connect.mail.pass", toAddress);
        props.setProperty("connect.max.msgs.in.batch", Integer.toString(MAX_NUM_MSGS_IN_BATCH));
        props.setProperty("connect.delete.unhandled.msgs", "false");
        props.setProperty("connect.mail.session.debug", "true");

        props.setProperty("mail.smtp.host", "localhost");
        props.setProperty("mail.smtp.auth", "TRUE");
        props.setProperty("mail.smtp.port", Integer.toString(smtpPort));
        props.setProperty("mail.smtp.starttls.enabled", "TRUE");

        props.setProperty("mail.imaps.host", "localhost");
        props.setProperty("mail.imaps.port", Integer.toString(imapPort));
        props.setProperty("mail.imaps.connectiontimeout", TIMEOUT_CONNECTION_MILLIS);
        props.setProperty("mail.imaps.timeout", TIMEOUT_MILLIS);

        // this allows us to run the test using a dummy in-memory keystore provided by GreenMail... don't use in prod.
        props.setProperty("mail.smtps.ssl.socketFactory.class",
                "com.icegreen.greenmail.util.DummySSLSocketFactory");
        props.setProperty("mail.smtps.ssl.socketFactory.port", Integer.toString(smtpPort));
        props.setProperty("mail.smtps.ssl.socketFactory.fallback", "false");
        props.setProperty("mail.imaps.ssl.socketFactory.class",
                "com.icegreen.greenmail.util.DummySSLSocketFactory");
        props.setProperty("mail.imaps.ssl.socketFactory.port", Integer.toString(imapPort));
        props.setProperty("mail.imaps.ssl.socketFactory.fallback", "false");

        return props;
    }
}

Related

  1. getFriendlyTime(long duration)
  2. getInsertionEndIndex(List list, Delayed key)
  3. getInStringSeconds(String pollInterval)
  4. getLastSlotDate(final int occurrences, final int periodicity, final long firstSlotDate, final int firstSlotDay, final String selectedDays)
  5. getLongFromQueue(BlockingQueue queue)
  6. getMinutes(final long milliseconds)
  7. getMinutesBetweenDates(Date begin_date, Date end_date)
  8. getMinutesBetweenDates(Date firstDate, Date secondDate)
  9. getNormalizedIntervalStartTimestamp(long intervalLengthMillis, long currentTimestamp)