Search in sources :

Example 1 with Provider

use of javax.mail.Provider 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 2 with Provider

use of javax.mail.Provider in project spring-boot by spring-projects.

the class MailHealthIndicatorTests method setup.

@Before
public void setup() {
    Session session = Session.getDefaultInstance(new Properties());
    session.addProvider(new Provider(Type.TRANSPORT, "success", SuccessTransport.class.getName(), "Test", "1.0.0"));
    this.mailSender = mock(JavaMailSenderImpl.class);
    given(this.mailSender.getHost()).willReturn("smtp.acme.org");
    given(this.mailSender.getPort()).willReturn(25);
    given(this.mailSender.getSession()).willReturn(session);
    this.indicator = new MailHealthIndicator(this.mailSender);
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Properties(java.util.Properties) Session(javax.mail.Session) Provider(javax.mail.Provider) Before(org.junit.Before)

Aggregations

Properties (java.util.Properties)2 Provider (javax.mail.Provider)2 Session (javax.mail.Session)2 NoSuchProviderException (javax.mail.NoSuchProviderException)1 NamingException (javax.naming.NamingException)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)1 SimpleNamingContextBuilder (org.springframework.mock.jndi.SimpleNamingContextBuilder)1