javax.mail.Transport.close()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(130)

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

Transport.close介绍

暂无

代码示例

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

Transport transport = session.getTransport("smtps");
transport.connect (smtp_host, smtp_port, smtp_username, smtp_password);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();

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

Transport transport = session.getTransport("smtp");
transport.connect("smtp.mail.yahoo.co.in", "user name", "asdfgh");
transport.sendMessage(message, message.getAllRecipients());
transport.close();

代码示例来源:origin: loklak/loklak_server

/**
 * Check SMTP login credentials
 * @param hostname the host address
 * @param username the username/login
 * @param password the password
 * @param encryption encryption type (must be none, starttls or tls)
 * @param port the port number
 * @param disableCertificateChecking disable certificate checking (behind a ssl-proxy or when the server has a self signed certificate)
 * @throws MessagingException on error
 */
public static void checkConnection(@Nonnull String hostname, @Nonnull String username,
                  @Nonnull String password, @Nonnull String encryption,
                  int port, boolean disableCertificateChecking) throws MessagingException{
  Properties props = createProperties(hostname, port, encryption, disableCertificateChecking);
  Session session = Session.getInstance(props, null);
  Transport transport = session.getTransport("smtp");
  transport.connect(username, password);
  transport.close();
}

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

Address[] to = InternetAddress.parse("me@localhost");
Transport t = session.getTransport(to[0]);
t.connect();
t.close();

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

private void sendMail(MailRequest mailRequest) {
  try {
    Session session = getSession();
    Transport transport = getTransport(session);
    try {
      MimeMessage msg = mailRequest.createMimeMessage(session);
      transport.sendMessage(msg, msg.getAllRecipients());
    } finally {
      transport.close();
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

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

public void init()
{
 if (_toList.size() == 0)
  throw new ConfigException(L.l("mail service requires at least one 'to' address"));
 _to = new Address[_toList.size()];
 _toList.toArray(_to);
 
 _from = new Address[_fromList.size()];
 _fromList.toArray(_from);
 try {
  if (_session == null) {
   _session = Session.getInstance(_properties);
  }
  Transport smtp = _session.getTransport("smtp");
  smtp.close();
 } catch (Exception e) {
  throw ConfigException.wrap(e);
 }
}

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

Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();

代码示例来源:origin: igniterealtime/Openfire

transport.connect(host, port, username, password);
for (MimeMessage message : messages) {
    transport.sendMessage(message,
      message.getRecipients(MimeMessage.RecipientType.TO));
if (transport != null) {
  try {
    transport.close();

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

int port = 587;
String host = "smtp.gmail.com";
String user = "username@gmail.com";
String pwd = "email password";

try {
  Properties props = new Properties();
  // required for gmail 
  props.put("mail.smtp.starttls.enable","true");
  props.put("mail.smtp.auth", "true");
  // or use getDefaultInstance instance if desired...
  Session session = Session.getInstance(props, null);
  Transport transport = session.getTransport("smtp");
  transport.connect(host, port, user, pwd);
  transport.close();
  System.out.println("success");
 } 
 catch(AuthenticationFailedException e) {
    System.out.println("AuthenticationFailedException - for authentication failures");
    e.printStackTrace();
 }
 catch(MessagingException e) {
    System.out.println("for other failures");
    e.printStackTrace();
 }

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

Transport transport;
try {
  transport = session.getTransport("smtp");
  transport.connect("smtp.gmail.com", username, password);
  transport.close();

  //Authentication success
} catch (AuthenticationException e) {
  System.out.println("Authentication Exception");
   //Authentication failed. Handle this here.
}

代码示例来源:origin: spring-projects/spring-framework

if (transport != null) {
      try {
        transport.close();
    transport.sendMessage(mimeMessage, (addresses != null ? addresses : new Address[0]));
try {
  if (transport != null) {
    transport.close();

代码示例来源:origin: com.caucho/resin

public void init()
{
 if (_toList.size() == 0)
  throw new ConfigException(L.l("mail service requires at least one 'to' address"));
 _to = new Address[_toList.size()];
 _toList.toArray(_to);
 
 _from = new Address[_fromList.size()];
 _fromList.toArray(_from);
 try {
  if (_session == null) {
   _session = Session.getInstance(_properties);
  }
  Transport smtp = _session.getTransport("smtp");
  smtp.close();
 } catch (Exception e) {
  throw ConfigException.create(e);
 }
}

代码示例来源:origin: apache/usergrid

msg.setSubject( subject );
Transport transport = session.getTransport();
  transport.connect( host, null, null );
}else{
  transport.connect( host, username, password );
transport.sendMessage( msg, msg.getAllRecipients() );
transport.close();
logger.info( String.format( LOG_PREFIX_OK + " Message-id: "+msg.getMessageID(), to ) );

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

public ValidationBean send(String subject, String body, String to) {
  Transport transport = null;
  try {
    LOGGER.debug("Sending email [{}] to [{}]", subject, to);
    Properties props = mailProperties();
    MailSession session = MailSession.getInstance().createWith(props, username, password);
    transport = session.getTransport();
    transport.connect(host, port, nullIfEmpty(username), nullIfEmpty(password));
    MimeMessage msg = session.createMessage(from, to, subject, body);
    transport.sendMessage(msg, msg.getRecipients(TO));
    return ValidationBean.valid();
  } catch (Exception e) {
    LOGGER.error("Sending failed for email [{}] to [{}]", subject, to, e);
    return ValidationBean.notValid(ERROR_MESSAGE);
  } finally {
    if (transport != null) {
      try {
        transport.close();
      } catch (MessagingException e) {
        LOGGER.error("Failed to close transport", e);
      }
    }
  }
}

代码示例来源:origin: com.caucho/resin

/**
 * Sends to a mailbox
 */
public void send(Message message)
{
 Transport smtp = null;
 try {
  smtp = _session.getTransport("smtp");
  smtp.connect();
  smtp.send(message, _to);
  log.fine(this + " sent mail to " + _to[0]);
 } catch (RuntimeException e) {
  throw e;
 } catch (Exception e) {
  throw new RuntimeException(e);
 } finally {
  try {
   if (smtp != null)
    smtp.close();
  } catch (Exception e) {
   log.log(Level.FINER, e.toString(), e);
  }
 }
}

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

@Test
public void connected() throws MessagingException {
  mailSender.smtpEnabled = true;
  when(objectFactoryMock.getSmtpTransport()).thenReturn(transportMock);
  mailSender.init();
  ExternalServiceStatus result = mailSender.getServiceStatus();
  assertThat(result, is(ExternalServiceStatus.CONNECTED));
  verify(objectFactoryMock).getSmtpTransport();
  verify(transportMock).connect(any(String.class), any(Integer.class), any(String.class), any(String.class));
  verify(transportMock).close();
  verifyNoMoreInteractions(objectFactoryMock, transportMock);
}

代码示例来源:origin: org.springframework/spring-context-support

if (transport != null) {
      try {
        transport.close();
    transport.sendMessage(mimeMessage, (addresses != null ? addresses : new Address[0]));
try {
  if (transport != null) {
    transport.close();

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

final Transport tr = session.getTransport(protocol);
try {
  tr.connect(session.getProperty("mail." + protocol + ".user"),
      session.getProperty("mail." + protocol + ".password"));
  tr.sendMessage(msg, msg.getAllRecipients());
} finally {
  tr.close();

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

Transport t = session.getTransport();
t.connect();
try {
 for(Message m : messages) {
  m.saveChanges();
  t.sendMessage(m, m.getAllRecipients());
 }
} finally {
 t.close();
}

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

/**
 * Sends to a mailbox
 */
public void send(Message message)
{
 Transport smtp = null;
 try {
  smtp = _session.getTransport("smtp");
  smtp.connect();
  smtp.send(message, _to);
  log.fine(this + " sent mail to " + _to[0]);
 } catch (RuntimeException e) {
  throw e;
 } catch (Exception e) {
  throw new RuntimeException(e);
 } finally {
  try {
   if (smtp != null)
    smtp.close();
  } catch (Exception e) {
   log.log(Level.FINER, e.toString(), e);
  }
 }
}

相关文章