List of usage examples for javax.mail Transport close
public synchronized void close() throws MessagingException
From source file:com.liferay.mail.imap.IMAPConnection.java
protected void testOutgoingConnection() throws MailException { StopWatch stopWatch = new StopWatch(); stopWatch.start();/*from ww w . j av a 2 s .c o m*/ try { Transport transport = getTransport(); transport.isConnected(); transport.close(); } catch (Exception e) { throw new MailException(MailException.ACCOUNT_OUTGOING_CONNECTION_FAILED, e); } finally { if (_log.isDebugEnabled()) { stopWatch.stop(); _log.debug("Testing outgoing connection completed in " + stopWatch.getTime() + " ms"); } } }
From source file:mx.unam.pixel.controller.MailController.java
public void enviaMensaje(String mensaje) { try {/*w w w. ja v a2s .com*/ Properties props = new Properties(); // Nombre del host de correo, es smtp.gmail.com props.setProperty("mail.smtp.host", "smtp.gmail.com"); // TLS si est disponible props.setProperty("mail.smtp.starttls.enable", "true"); // Puerto de gmail para envio de correos props.setProperty("mail.smtp.port", "587"); // Nombre del usuario props.setProperty("mail.smtp.user", "ejemplo@gmail.com"); // Si requiere o no usuario y password para conectarse. props.setProperty("mail.smtp.auth", "true"); // Preparamos la sesion Session session = Session.getDefaultInstance(props); //session.setDebug(true); //Construimos el mensage MimeMessage message = new MimeMessage(session); InternetAddress cuenta = new InternetAddress("enrique.wps@gmail.com"); message.setFrom(); //Correo electronico que manda el mensaja message.addRecipient(Message.RecipientType.TO, new InternetAddress("vampa@ciencias.unam.mx")); message.setSubject("Test MUFFIN"); message.setText("Test Muffin Cuerpo"); // Abrimos la comunicacion Transport t = session.getTransport("smtp"); t.connect("dasds@gmail.com", "asdsadas"); // Ususario y contrasea t.sendMessage(message, message.getAllRecipients()); // Cierre t.close(); } catch (AddressException ex) { System.err.println("er"); } catch (MessagingException ex) { Logger.getLogger(MailController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.wso2telco.workflow.notification.EmailService.java
public void sendEmail(final String emailAddress, final String subject, final String content) { new Thread() { @Override/*from w w w . j a v a 2 s . c o m*/ public void run() { Map<String, String> workflowProperties = WorkflowProperties.loadWorkflowPropertiesFromXML(); String emailHost = workflowProperties.get(Constants.KEY_WORKFLOW_EMAIL_NOTIFICATION_HOST); String fromEmailAddress = workflowProperties .get(Constants.KEY_WORKFLOW_EMAIL_NOTIFICATION_FROM_ADDRESS); String fromEmailPassword = workflowProperties .get(Constants.KEY_WORKFLOW_EMAIL_NOTIFICATION_FROM_PASSWORD); Properties props = System.getProperties(); props.put("mail.smtp.host", emailHost); props.put("mail.smtp.user", fromEmailAddress); props.put("mail.smtp.password", fromEmailPassword); props.put("mail.smtp.port", "587"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); try { Session session = Session.getDefaultInstance(props, null); InternetAddress toAddress = new InternetAddress(emailAddress); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(fromEmailAddress)); message.addRecipient(Message.RecipientType.TO, toAddress); message.setSubject(subject); message.setContent(content, "text/html; charset=UTF-8"); Transport transport = session.getTransport("smtp"); transport.connect(emailHost, fromEmailAddress, fromEmailPassword); transport.sendMessage(message, message.getAllRecipients()); transport.close(); } catch (Exception e) { log.error("Email sending failed. ", e); } } }.start(); }
From source file:org.openengsb.connector.email.internal.abstraction.JavaxMailAbstraction.java
private void send(Message message, Session session) throws MessagingException { log.info("sending email-message"); message.saveChanges();//from w w w .j a v a 2 s.c om Transport transport = getTransport(session); transport.sendMessage(message, message.getAllRecipients()); transport.close(); log.info("email has been sent"); }
From source file:com.warsaw.data.controller.LoginController.java
private boolean sendEmail(String to) { Properties properties = System.getProperties(); // Setup mail server properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.host", HOST); properties.put("mail.smtp.user", EMAIL); properties.put("mail.smtp.password", PASS); properties.put("mail.smtp.port", "587"); properties.put("mail.smtp.auth", "true"); properties.setProperty("mail.transport.protocol", "smtp"); // Get the default Session object. Session session = Session.getDefaultInstance(properties); try {/*from w ww .ja v a 2s . c o m*/ Message msg = this.buildEmail(session, to); /* Transport transport = session.getTransport(); transport.send(msg);*/ Transport transport = session.getTransport("smtp"); transport.connect(HOST, EMAIL, PASS); transport.sendMessage(msg, msg.getAllRecipients()); transport.close(); } catch (Exception e) { System.out.println("Ex :" + e); return false; } return true; }
From source file:com.fstx.stdlib.common.messages.MailSenderImpl.java
/** * @see com.ess.messages.MailSender#send() *//*from w w w .j a v a2 s .co m*/ public boolean send() { try { // 2005-11-27 RSC always requires authentication. Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", host.getAddress()); /* * 2005-11-27 RSC * Since webmail.us is starting to make other ports available * as Comcast blocks port 25. */ props.put("mail.smtp.port", host.getPort()); Session s = Session.getInstance(props, null); MimeMessage messageOut = new MimeMessage(s); InternetAddress fromOut = new InternetAddress(from.getAddress()); //reid 2004-12-20 fromOut.setPersonal(from.getName()); messageOut.setFrom(fromOut); InternetAddress toOut = new InternetAddress(this.to.getAddress()); //reid 2004-12-20 toOut.setPersonal(to.getName()); messageOut.addRecipient(javax.mail.Message.RecipientType.TO, toOut); messageOut.setSubject(message.getSubject()); messageOut.setText(message.getMessage()); if (host.useAuthentication()) { Transport transport = s.getTransport("smtp"); transport.connect(host.getAddress(), host.getUsername(), host.getPassword()); transport.sendMessage(messageOut, messageOut.getAllRecipients()); transport.close(); } else { Transport.send(messageOut); } } catch (Exception e) { log.info("\n\nMailSenderIMPL3: " + host.getAddress()); e.printStackTrace(); throw new RuntimeException(e); } return true; }
From source file:net.sourceforge.subsonic.backend.service.EmailSession.java
private void sendMessage(MimeMessage message) throws MessagingException { Transport transport = null; try {// w w w . j a v a2s .c o m transport = session.getTransport("smtps"); transport.connect(USER, password); transport.sendMessage(message, message.getAllRecipients()); } finally { if (transport != null) { transport.close(); } } }
From source file:com.fsrin.menumine.common.message.MailSenderImpl.java
/** * @see com.ess.messages.MailSender#send() */// w w w . ja v a 2 s.c o m public boolean send() { try { Properties props = new Properties(); props.put("mail.smtp.host", host.getAddress()); if (host.useAuthentication()) { props.put("mail.smtp.auth", "true"); } Session s = Session.getInstance(props, null); s.setDebug(true); // PasswordAuthentication pa = new PasswordAuthentication(host // .getUsername(), host.getPassword()); // // URLName url = new URLName(host.getAddress()); // // s.setPasswordAuthentication(url, pa); MimeMessage messageOut = new MimeMessage(s); InternetAddress fromOut = new InternetAddress(from.getAddress()); //reid 2004-12-20 fromOut.setPersonal(from.getName()); messageOut.setFrom(fromOut); InternetAddress toOut = new InternetAddress(this.to.getAddress()); //reid 2004-12-20 toOut.setPersonal(to.getName()); messageOut.addRecipient(javax.mail.Message.RecipientType.TO, toOut); messageOut.setSubject(message.getSubject()); messageOut.setText(message.getMessage()); if (host.useAuthentication()) { Transport transport = s.getTransport("smtp"); transport.connect(host.getAddress(), host.getUsername(), host.getPassword()); transport.sendMessage(messageOut, messageOut.getAllRecipients()); transport.close(); } else { Transport.send(messageOut); } } catch (Exception e) { log.info("\n\nMailSenderIMPL3: " + host.getAddress()); e.printStackTrace(); throw new RuntimeException(e); } return true; }
From source file:mx.uatx.tesis.managebeans.RecuperarCuentaMB.java
public void enviarCorreo(String nombre, String apellido, String corre, String password2) throws Exception { String passwordDesencriptada = Desencriptar(password2); try {// www .java2s .c om // Propiedades de la conexin Properties props = new Properties(); props.setProperty("mail.smtp.host", "smtp.gmail.com"); props.setProperty("mail.smtp.starttls.enable", "true"); props.setProperty("mail.smtp.port", "587"); props.setProperty("mail.smtp.user", "alfons018pbg@gmail.com"); props.setProperty("mail.smtp.auth", "true"); // Preparamos la sesion Session session = Session.getDefaultInstance(props); // Construimos el mensaje MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress("alfons018pbg@gmail.com")); message.addRecipient(Message.RecipientType.TO, new InternetAddress("" + corre + "")); message.setSubject("Asistencia tcnica"); message.setText("\n \n \n Estimado: " + nombre + " " + apellido + "\n El Servicio Tecnico de SEA ha recibido tu solicitud. " + "\n Los siguientes son tus datos para acceder:" + "\n Correo: " + corre + "\n Password: " + passwordDesencriptada + ""); // Lo enviamos. Transport t = session.getTransport("smtp"); t.connect("alfons018pbg@gmail.com", "al12fo05zo1990"); t.sendMessage(message, message.getAllRecipients()); // Cierre. t.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.agiletec.plugins.jpwebmail.aps.system.services.webmail.WebMailManager.java
/** * Effettua la chiusura controllata del transport. * @param transport Il Transport da chiudere. * @throws ApsSystemException In caso di errore in chiusura. *///from w w w . ja va 2s .c om protected void closeTransport(Transport transport) throws ApsSystemException { if (transport != null) { try { transport.close(); } catch (MessagingException e) { _logger.error("Error closing connection", e); throw new ApsSystemException("Error closing connection", e); } } }