Java Code Examples for org.springframework.mail.javamail.JavaMailSenderImpl#testConnection()

The following examples show how to use org.springframework.mail.javamail.JavaMailSenderImpl#testConnection() . 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: AbstractMailService.java    From halo with GNU General Public License v3.0 8 votes vote down vote up
/**
 * Test connection with email server.
 */
@Override
public void testConnection() {
    JavaMailSender javaMailSender = getMailSender();
    if (javaMailSender instanceof JavaMailSenderImpl) {
        JavaMailSenderImpl mailSender = (JavaMailSenderImpl) javaMailSender;
        try {
            mailSender.testConnection();
        } catch (MessagingException e) {
            throw new EmailException("无法连接到邮箱服务器,请检查邮箱配置.[" + e.getMessage() + "]", e);
        }
    }
}
 
Example 2
Source File: JavaMailSenderFactory.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void validateConnection(MailSettings mailSettings) {
  LOG.info("Validating mail settings...");
  try {
    JavaMailSenderImpl sender = createMailSender(mailSettings);
    sender.testConnection();
    LOG.info("OK.");
  } catch (MessagingException ex) {
    String message = format("Unable to ping to %s", mailSettings.getHost());
    LOG.info(message, ex);
    throw new IllegalStateException(message, ex);
  }
}