Examples of Transport


Examples of javax.mail.Transport

                log("ERROR: " + lookup.getErrorString() + " when lookup MX record of " + email);
                continue;
              }
              Record[] answers = lookup.getAnswers();
              for(int ai=0;ai<answers.length;ai++){
                Transport transport = null;
                    log("Using " + answers[i].getAdditionalName()+" to send mail to " + email);
                    String mx_host = answers[i].getAdditionalName().toString();
                    mailSession.getProperties().put("mail.smtp.host", mx_host);
                    InternetAddress smtp_host = new InternetAddress(mx_host);
                    try {
                        transport = mailSession.getTransport(smtp_host);
                        try {
                            transport.connect();
                            log("INFO: connected to "+mx_host);
                        } catch (MessagingException me) {
                            // Any error on connect should cause the mailet to attempt
                            // to connect to the next SMTP server associated with this
                            // MX record.  Just log the exception.  We'll worry about
                            // failing the message at the end of the loop.
                            me.printStackTrace();
                            log("ERROR: Connecto to " + mx_host + " failed." , me);
                            continue;
                        }
                        InternetAddress mailToAddress = new InternetAddress(email);           
                        transport.sendMessage(mail, new InternetAddress[]{mailToAddress});
                        log("INFO: mail sent to " + email);
                        break;
                    } finally {
                        if (transport != null) {
                            transport.close();
                            transport = null;
                        }
                    }
              }
            }
View Full Code Here

Examples of javax.mail.Transport

        System.out.println(" " + lookup.getErrorString());
        return;
      }
      Record[] answers = lookup.getAnswers();
      for(int i=0;i<answers.length;i++){
            Transport transport = null;
            //System.out.println("Using " + answers[i].getAdditionalName()+" to send...");
            ssn.getProperties().put("mail.smtp.host", answers[i].getAdditionalName().toString());
            InternetAddress smtp_host = new InternetAddress(answers[i].getAdditionalName().toString());
            try {
                transport = ssn.getTransport(smtp_host);
                  transport.connect();
                  System.out.println("connect to "+smtp_host+" ok.");
                InternetAddress mailToAddress = new InternetAddress(mailaddr);           
                transport.sendMessage(mailMessage, new InternetAddress[]{mailToAddress});
                System.out.println("mail sent to " + mailaddr + " via " + smtp_host);
                break;
              } catch (MessagingException me) {
                  // Any error on connect should cause the mailet to attempt
                  // to connect to the next SMTP server associated with this
                  // MX record.  Just log the exception.  We'll worry about
                  // failing the message at the end of the loop.
                  me.printStackTrace();
            } finally {
                if (transport != null) {
                    transport.close();
                    transport = null;
                }
            }
      }
    }
View Full Code Here

Examples of javax.mail.Transport


    DataSource htmlDataSource = getHtmlDataSource(loginLink);
    DataSource textDataSource = getTextDataSource(loginLink);

    Transport transport;
    try {
      transport = session.getTransport();
      transport.connect();
      log.debug("connected");
    } catch (MessagingException e) {
      log.error("Error Opening transport for sending "+loginLink+" ("+e.toString()+")");
      throw new RuntimeException("Opening Transport", e);
    }
    try {
        InternetAddress address = new InternetAddress(email);

        Message msg = new MimeMessage(session);

        msg.setFrom(new InternetAddress(configuration.getFromAddress()));

        msg.setRecipient(Message.RecipientType.TO, address);
        String title = "GVS Login Link";
        try {
          msg.setSubject(MimeUtility.encodeText(title, "UTF-8", null));
        } catch (UnsupportedEncodingException e) {
          throw new RuntimeException(e);

        }
        msg.setSentDate(new java.util.Date());
        // create and fill the first message part

        MimeBodyPart plainTextVersion = new MimeBodyPart();
        plainTextVersion.setDataHandler(new DataHandler(textDataSource));

        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setDataHandler(new DataHandler(htmlDataSource));
        // create the Multipart
        // and its parts to it
        Multipart bodyAlternatives = new MimeMultipart("alternative");
        bodyAlternatives.addBodyPart(plainTextVersion);
        htmlPart.setHeader("Content-Type", "text/html; charset=UTF-8");
        bodyAlternatives.addBodyPart(htmlPart);



        // mbp1.setHeader("Content-Language", "fr");
        // add the Multipart to the message
        Multipart mainMultipart = new MimeMultipart();
        BodyPart body = new MimeBodyPart();
        body.setContent(bodyAlternatives);
        mainMultipart.addBodyPart(body);

        // mainMultipart.addBodyPart(getSerialializerRDFPart(mailModel));

        msg.setContent(mainMultipart);
        log.debug("mesage ready, sending");
        Transport.send(msg);
        /*
         * Reusing conncection: (problem:isp limits) Address[] recipients = new
         * Address[1]; recipients[0] = recipient; transport.sendMessage(msg,
         * recipients);
         */
        log.info("message sent to " + address.getAddress() + " ("
            + Thread.activeCount() + ")");
      } catch (Exception ex) {
        log.error("sending email: ", ex);
      }
    try {
      transport.close();
    } catch (MessagingException e) {
      log.error("closing transport: ", e);
    }
  }
View Full Code Here

Examples of javax.mail.Transport

            collect( message.getBody(), msg );
            msg.setHeader( "X-Mailer", mailer );
            msg.setSentDate( new Date() );
           
            // send the thing off
          Transport t = (Transport)session.getTransport("smtp");
          try {
            t.connect(mailhost, username, password);
          t.sendMessage(msg, msg.getAllRecipients());
          } catch (Exception e) {
            throw new RuntimeException( "Connection failure", e );
           } finally {
            t.close();
          }

        } catch ( Exception e ) {
            throw new RuntimeException( "Unable to send email", e );
        }
View Full Code Here

Examples of javax.mail.Transport

    baseMsg.setSubject("Test Big attached file message");
    baseMsg.setContent(multipart);
    baseMsg.saveChanges();

    log.debug("Send started");
    Transport t = new SMTPTransport(session, new URLName("smtp://localhost:"+SMTP_PORT));
    long started = System.currentTimeMillis();
    t.connect();
    t.sendMessage(baseMsg, new Address[] {new InternetAddress(
        "success@subethamail.org")});
    t.close();
    started = System.currentTimeMillis() - started;
    log.info("Elapsed ms = "+started);

    WiserMessage msg = this.server.getMessages().get(0);
View Full Code Here

Examples of javax.mail.Transport

      // session.setDebug(true);

      mimeMessages[0] = this.createMessage(session, "sender@whatever.com", "receiver@home.com", "Doodle1", "Bug1");
      mimeMessages[1] = this.createMessage(session, "sender@whatever.com", "receiver@home.com", "Doodle2", "Bug2");

      Transport transport = session.getTransport("smtp");
      transport.connect("localhost", SMTP_PORT, null, null);

      for (MimeMessage mimeMessage : mimeMessages)
      {
        transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
      }

      transport.close();
    }
    catch (MessagingException e)
    {
      e.printStackTrace();
      fail("Unexpected exception: " + e);
View Full Code Here

Examples of javax.mail.Transport

      msg.setText(body);
      msg.setHeader("X-Mailer", "musala");
      msg.setSentDate(new Date());

      Transport transport = null;

      try
      {
        transport = session.getTransport("smtp");
        transport.connect(HOST_NAME, SMTP_PORT, "ddd", "ddd");
        assertEquals(0, this.server.getMessages().size());
        transport.sendMessage(msg, InternetAddress.parse(To, false));
        assertEquals(1, this.server.getMessages().size());
        transport.sendMessage(msg, InternetAddress.parse("dimiter.bakardjiev@musala.com", false));
        assertEquals(2, this.server.getMessages().size());
      }
      catch (javax.mail.MessagingException me)
      {
        me.printStackTrace();
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
      finally
      {
        if (transport != null)
          transport.close();
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
View Full Code Here

Examples of javax.mail.Transport

         newMessage.setSentDate(new java.util.Date());
         newMessage.setText(message);

         // Send newMessage
          //
          Transport transport = session.getTransport();
          transport.connect();
          transport.sendMessage(newMessage, to);
      }
      catch (Exception ex)
      {
         ex.printStackTrace();
      }
View Full Code Here

Examples of javax.mail.Transport

        if( !started ) {
            throw new RuntimeException("This mail sender is stopped");
        }
        try {
            log.debug("sending to: " + host);
            Transport tr = getSession().getTransport("smtp");
            tr.connect(host, port, user, password);
            mm.saveChanges();
            tr.sendMessage(mm, mm.getAllRecipients());
            tr.close();
        } catch (MessagingException ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here

Examples of jetbrains.communicator.core.transport.Transport

    myActions.add(new CreateGroupAction());
    myActions.add(new BaseAction<FindUsersCommand>(FindUsersCommand.class));

    List instancesOfType = Pico.getInstance().getComponentInstancesOfType(Transport.class);
    for (Object aInstancesOfType : instancesOfType) {
      Transport transport = (Transport) aInstancesOfType;
      Class<? extends NamedUserCommand> specificFinderClass = transport.getSpecificFinderClass();
      if (specificFinderClass != null) {
        myActions.add(new BaseAction(specificFinderClass));
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.