org.apache.commons.mail.HtmlEmail.getMailSession()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.0k)|赞(0)|评价(0)|浏览(74)

本文整理了Java中org.apache.commons.mail.HtmlEmail.getMailSession()方法的一些代码示例,展示了HtmlEmail.getMailSession()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HtmlEmail.getMailSession()方法的具体详情如下:
包路径:org.apache.commons.mail.HtmlEmail
类名称:HtmlEmail
方法名:getMailSession

HtmlEmail.getMailSession介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

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");

代码示例来源:origin: stackoverflow.com

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");

代码示例来源:origin: inspectIT/inspectIT

email.getMailSession().getProperties().putAll(additionalProperties);

代码示例来源:origin: inspectIT/inspectIT

@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));
}

代码示例来源:origin: inspectIT/inspectIT

@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);

代码示例来源:origin: inspectIT/inspectIT

@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");

相关文章