HtmlEmail email = new HtmlEmail(); String authuser = "user"; String authpwd = "pass"; email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd)); email.setHostName("smtp.gmail.com"); // properties to configure encryption email.getMailSession().getProperties().put("mail.smtps.auth", "true"); email.getMailSession().getProperties().put("mail.debug", "true"); email.getMailSession().getProperties().put("mail.smtps.port", "587"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.port", "587"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.fallback", "false"); email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true");
email.getMailSession().getProperties().put("mail.smtps.auth", "true"); email.getMailSession().getProperties().put("mail.debug", "true"); email.getMailSession().getProperties().put("mail.smtps.port", "587"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.port", "587"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.fallback", "false"); email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true");
email.getMailSession().getProperties().putAll(additionalProperties);
@Test public void emptyRecipients() throws Exception { Session session = Session.getInstance(new Properties()); when(mailMock.getMailSession()).thenReturn(session); when(objectFactoryMock.createHtmlEmail()).thenReturn(mailMock); when(objectFactoryMock.getSmtpTransport()).thenReturn(transportMock); mailSender.defaultRecipientString = ""; mailSender.smtpHost = "host"; mailSender.smtpPort = 25; mailSender.smtpUser = "user"; mailSender.smtpPassword = "passwd"; mailSender.senderAddress = "sender@example.com"; mailSender.senderName = "Sender Name"; mailSender.smtpEnabled = true; mailSender.init(); boolean result = mailSender.sendEMail("subject", "htmlBody", "textBody", Collections.emptyList()); assertThat(result, is(false)); assertThat(mailSender.getServiceStatus(), is(ExternalServiceStatus.CONNECTED)); }
@Test public void sendWithoutDefaultRecipientsAndProperties() throws Exception { Session session = Session.getInstance(new Properties()); when(mailMock.getMailSession()).thenReturn(session); when(objectFactoryMock.createHtmlEmail()).thenReturn(mailMock); when(objectFactoryMock.getSmtpTransport()).thenReturn(transportMock);
@Test public void sendUsingDefaultRecipientsAndProperties() throws Exception { Session session = Session.getInstance(new Properties()); when(mailMock.getMailSession()).thenReturn(session); when(objectFactoryMock.createHtmlEmail()).thenReturn(mailMock); when(objectFactoryMock.getSmtpTransport()).thenReturn(transportMock); verify(mailMock).setAuthentication("user", "passwd"); verify(mailMock).setFrom("sender@example.com", "Sender Name"); verify(mailMock).getMailSession(); verify(mailMock).addTo("one@example.com"); verify(mailMock).addTo("two@example.com");