Package javax.mail

Examples of javax.mail.Transport


        doEventTests(TransportEvent.MESSAGE_NOT_DELIVERED);
    }
    private void doEventTests(int type) throws AddressException {
        Folder folder = TestData.getTestFolder();
        Message message = TestData.getMessage();
        Transport transport = TestData.getTestTransport();
        Address[] sent = new Address[] { new InternetAddress("alex@here.com")};
        Address[] empty = new Address[0];
        TransportEvent event =
            new TransportEvent(transport, type, sent, empty, empty, message);
        assertEquals(transport, event.getSource());
View Full Code Here


            message.addRecipient(Message.RecipientType.TO, toAddress[i]);
        }
       
        message.setSubject(subject);
        message.setText(emailBody.toString());
        Transport transport = session.getTransport("smtp");
        transport.connect(host, from, pass);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
     
     }catch(MessagingException ex)
     {
       System.out.println(ex.getMessage());
     }
View Full Code Here

        int nAddresses = remainingAddresses.length;
        boolean bFailedToSome = false;
       
        SendFailedException sendex = new SendFailedException("Unable to send message to some recipients");
       
        Transport transport = mailProvider.getTransport();
       
        // Try to send while there remain some potentially good addresses
        try {
            do {
                // Avoid a loop if we are stuck
                nAddresses = remainingAddresses.length;

                try {
                    // Send to the list of remaining addresses, ignoring the addresses attached to the message
                    transport.send(message, remainingAddresses);
                } catch(SendFailedException ex) {
                    bFailedToSome=true;
                    sendex.setNextException(ex);

                    // Extract the remaining potentially good addresses
                    remainingAddresses=ex.getValidUnsentAddresses();
                }
            } while (remainingAddresses!=null && remainingAddresses.length>0 && remainingAddresses.length!=nAddresses);
           
        } finally {
            transport.close();
        }
       
        if (bFailedToSome) throw sendex;
    }
View Full Code Here

   */
  protected void send(final Session session, final MimeMessage msg) {
    try {
      final URLName smtpUrlName = options.genSmtpUrlName();
      log.debug("Opening transport to: " + smtpUrlName);
      final Transport transport = session.getTransport(smtpUrlName);
      transport.connect(smtpUrlName.getHost(), smtpUrlName.getPort(),
          smtpUrlName.getUsername(), smtpUrlName.getPassword());
      transport.sendMessage(msg, msg.getAllRecipients());
      transport.close();
      log.info("Message sent");
    } catch (Exception e) {
      log.error("Unable to send message", e);
    } finally {
      // readyToListen();
View Full Code Here

       
        // Setting the Subject and Content Type
        msg.setSubject(subject);
        msg.setContent(multipart);
       
        Transport transport = session.getTransport(addressTo[0]);
        transport.addTransportListener(this);
        transport.connect();
        // Sending Message
        for(Address to: addressTo) {
          try{
          //msg.setRecipients(RecipientType.TO,new Address[]{to});
          //Transport.send(msg);
            msg.setRecipients(RecipientType.TO,new Address[]{to});
            transport.sendMessage(msg,new Address[]{to});
          } catch (Exception e) {
            //messageSendFailed(e,msg);
            transport.close();
                transport.connect();
          }
        }
        transport.close();
    }
View Full Code Here

   * @return
   * @throws NoSuchProviderException
   * @throws MessagingException
   */
  public boolean send(MailMessage[] mailMessage){
    Transport transport = null;
    boolean sendSuccess = true;
    try {
      Properties props = new Properties();
      props.put("mail." + this.protocol + ".auth", "true");
      props.put("mail.transport.protocol", this.protocol);
      props.put("mail." + this.protocol + ".host", this.smtpHost);
      props.put("mail." + this.protocol + ".port", String.valueOf(this.port));
      Session session = Session.getDefaultInstance(props, null);
      transport = session.getTransport(this.protocol);
      transport.connect(this.smtpHost, this.userName, this.passWord);
     
      for (int i = 0; i < mailMessage.length; ++i) {
        mailMessage[i].setSession(session);
        transport.sendMessage(mailMessage[i].getMessage(),mailMessage[i].getMessage().getAllRecipients());
      }
    } catch (Exception e) {
      log.error("发送多份邮件失败"+e.getMessage());
      e.printStackTrace();
      sendSuccess = false;
    } finally {
      if (transport != null){
        try {
          transport.close();
        } catch (MessagingException e) {
          log.error("发送多份邮件出现异常"+e.getMessage());
        }
      }
    }
View Full Code Here

            Debug.logVerbose("What would have been sent, the addressee: " + sendTo + " subject: " + subject + " context: " + context, module);
            results.put("messageWrapper", new MimeMessageWrapper(session, mail));
            return results;
        }

        Transport trans = null;
        try {
            trans = session.getTransport("smtp");
            if (!useSmtpAuth) {
                trans.connect();
            } else {
                trans.connect(sendVia, authUser, authPass);
            }
            trans.sendMessage(mail, mail.getAllRecipients());
            results.put("messageWrapper", new MimeMessageWrapper(session, mail));
            results.put("messageId", mail.getMessageID());
            trans.close();
        } catch (SendFailedException e) {
            // message code prefix may be used by calling services to determine the cause of the failure
            Debug.logError(e, "[ADDRERR] Address error when sending message to [" + sendTo + "] from [" + sendFrom + "] cc [" + sendCc + "] bcc [" + sendBcc + "] subject [" + subject + "]", module);
            List<SMTPAddressFailedException> failedAddresses = FastList.newInstance();
            Exception nestedException = null;
            while ((nestedException = e.getNextException()) != null && nestedException instanceof MessagingException) {
                if (nestedException instanceof SMTPAddressFailedException) {
                    SMTPAddressFailedException safe = (SMTPAddressFailedException) nestedException;
                    Debug.logError("Failed to send message to [" + safe.getAddress() + "], return code [" + safe.getReturnCode() + "], return message [" + safe.getMessage() + "]", module);
                    failedAddresses.add(safe);
                    break;
                }
            }
            Boolean sendFailureNotification = (Boolean) context.get("sendFailureNotification");
            if (sendFailureNotification == null || sendFailureNotification) {
                sendFailureNotification(ctx, context, mail, failedAddresses);
                results.put("messageWrapper", new MimeMessageWrapper(session, mail));
                try {
                    results.put("messageId", mail.getMessageID());
                    trans.close();
                } catch (MessagingException e1) {
                    Debug.logError(e1, module);
                }
            } else {
                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendAddressError", UtilMisc.toMap("sendTo", sendTo, "sendFrom", sendFrom, "sendCc", sendCc, "sendBcc", sendBcc, "subject", subject), locale));
View Full Code Here

        Store store = ((Session) proxy).getStore();
        assertNotNull(store);
        assertTrue(store instanceof TestStore);

        Transport transport = ((Session) proxy).getTransport();
        assertNotNull(transport);
        assertTrue(transport instanceof TestTransport);

    }
View Full Code Here

        Store store = ((Session) proxy).getStore();
        assertNotNull(store);
        assertTrue(store instanceof TestStore);

        Transport transport = ((Session) proxy).getTransport();
        assertNotNull(transport);
        assertTrue(transport instanceof TestTransport);

    }
View Full Code Here

        Store store = ((Session) proxy).getStore();
        assertNotNull(store);
        assertTrue(store instanceof TestStore);

        Transport transport = ((Session) proxy).getTransport();
        assertNotNull(transport);
        assertTrue(transport instanceof TestTransport);

        TestTransport testTransport = (TestTransport) transport;
        assertFalse(testTransport.isEHLO());
View Full Code Here

TOP

Related Classes of javax.mail.Transport

Copyright © 2018 www.massapicom. 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.