javax.mail.Provider.Type Java Examples

The following examples show how to use javax.mail.Provider.Type. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ForgotPasswordCommand.java    From FlexibleLogin with MIT License 5 votes vote down vote up
private Session buildSession(MailConfig emailConfig) {
    Properties properties = new Properties();
    properties.setProperty("mail.smtp.host", emailConfig.getHost());
    properties.setProperty("mail.smtp.auth", "true");
    properties.setProperty("mail.smtp.port", String.valueOf(emailConfig.getPort()));

    //ssl
    properties.setProperty("mail.smtp.socketFactory.port", String.valueOf(emailConfig.getPort()));
    properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    properties.setProperty("mail.smtp.socketFactory.fallback", "false");
    properties.setProperty("mail.smtp.starttls.enable", String.valueOf(true));
    properties.setProperty("mail.smtp.ssl.checkserveridentity", "true");

    //we only need to send the message so we use smtps
    properties.setProperty("mail.transport.protocol", "smtps");

    //explicit override stmp provider because of issues with relocation
    Session session = Session.getDefaultInstance(properties);
    try {
        session.setProvider(new Provider(Type.TRANSPORT, "smtps",
                "flexiblelogin.mail.smtp.SMTPSSLTransport", "Oracle", "1.6.0"));
    } catch (NoSuchProviderException noSuchProvider) {
        logger.error("Failed to add SMTP provider", noSuchProvider);
    }

    return session;
}
 
Example #2
Source File: MailSenderTest.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public MailSender createSender() throws Exception {
	MailSender mailSender = new MailSender() {
		Session mailSession;
		@Override
		protected Session createSession() throws SenderException {
			try {
				mailSession = super.createSession();
				Provider provider = new Provider(Type.TRANSPORT, "smtp", TransportMock.class.getCanonicalName(), "IbisSource.org", "1.0");
				mailSession.setProvider(provider);

				return mailSession;
			} catch(Exception e) {
				e.printStackTrace();
				throw new SenderException(e);
			}
		}

		@Override
		public Message sendMessage(Message message, IPipeLineSession session) throws SenderException, TimeOutException {
			super.sendMessage(message, session);
			session.put("mailSession", mailSession);
			String correlationID = session.getMessageId();
			return new Message(correlationID);
		}
	};
	mailSender.setSmtpHost("localhost");
	mailSender.setSmtpUserid("user123");
	mailSender.setSmtpPassword("secret321");
	return mailSender;
}