Package javax.mail

Examples of javax.mail.Transport


                     if (bccAddresses != null)
                     {
                        message.addRecipients(Message.RecipientType.BCC, InternetAddress.parse(bccAddresses));
                     }
                     Transport transport = session.getTransport("smtp");
                     if (doLogin)
                     {
                        transport.connect(serverHost, serverPort, serverUserName, serverPassword);
                     }
                     else
                     {
                        transport.connect();
                     }
                     message.saveChanges();

                     if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Sending message");
                     transport.sendMessage(message, message.getAllRecipients());
                     transport.close();
                     if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Message sent");
                  }
                  catch (Exception e)
                  {
                     logger.error("Exception during message sending ", e);
View Full Code Here


     * @throws IOException
     * @throws InterruptedException
     */
    public void execute(Message message) throws MessagingException, IOException, InterruptedException {

        Transport tr = session.getTransport(getProtocol());
        SynchronousTransportListener listener = null;

        if (synchronousMode) {
            listener = new SynchronousTransportListener();
            tr.addTransportListener(listener);
        }

        if (useAuthentication) {
            tr.connect(smtpServer, username, password);
        } else {
            tr.connect();
        }

        tr.sendMessage(message, message.getAllRecipients());

        if (listener != null /*synchronousMode==true*/) {
            listener.attend(); // listener cannot be null here
        }

        tr.close();
        logger.debug("transport closed");

        logger.debug("message sent");
        return;
    }
View Full Code Here

        for( int i=0; i < toAddress.length; i++) { // changed from a while loop
            message.addRecipient(Message.RecipientType.TO, toAddress[i]);
        }
        message.setSubject("SGI Evaluation");
        message.setText(text);
        Transport transport = session.getTransport("smtp");
        transport.connect(host, from, pass);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
    }
View Full Code Here

                auth = null;
            }

            final Session session = Session.getInstance(props, auth);
            session.setDebug(isDebug());
            final Transport transport = session.getTransport("smtp");
            try {
                transport.connect();
                int count = _addresses.size();
                for (int i = 0; i < count; i++) {
                    final String mailAddress = _addresses.get(i);
                    final InternetAddress[] addressTo = new InternetAddress[1];
                    addressTo[0] = new InternetAddress(mailAddress);
                    final InternetAddress addressFrom = new InternetAddress(_from);
                    // Construct the message
                    final Message msg = new MimeMessage(session);
                    msg.setSentDate(new Date());
                    msg.setDescription(MSG_DESCRIPTION);
                    msg.setFrom(addressFrom);
                    msg.setReplyTo(new InternetAddress[] {addressFrom});
                    msg.setRecipients(Message.RecipientType.TO, addressTo);

                    msg.setSubject(_subject);

                    //msg.setContent(_message, _mailFormat.toString());
                    final Multipart mp = this.getMailMultiPart();

                    msg.setContent(mp);

                    // Send the message
                    Transport.send(msg);
                }
                return true;
            } finally {
                try {
                    transport.close();
                } catch (MessagingException ex) {
                }
            }
        } catch (Throwable t) {
            final String msg = StringUtils.format("SEND EMAIL ERROR: " +
View Full Code Here

            this.ignoreHooksCount--;
                return;
            }

            Session session = Session.getDefaultInstance(props, null);
            Transport trans = session.getTransport("smtp");
            trans.connect();

            this.smtpMessage = setUpMessage(session);

          this.ignoreHooksCount++;
            super.sendStartElementEventNS(ELEMENT_RESULT);

            if (this.sendPartial) {
                for (int i = 0; i < this.toAddresses.size(); i++) {
                    List v = new ArrayList(1);
                    v.add(this.toAddresses.get(i));
                    sendMail(v, trans);
                }
            } else {
                sendMail(this.toAddresses, trans);
            }

            trans.close();
            super.sendEndElementEventNS(ELEMENT_RESULT);
            this.ignoreHooksCount--;
        } catch (Exception e) {
            getLogger().error("Exception sending mail", e);
            sendExceptionElement(e);
View Full Code Here

                attachments.addBodyPart(body);
            }
            msg.setContent(attachments);
            try {
                // Send the message using SMTP, or SMTPS if the host uses SSL
                Transport transport = sesh.getTransport(SSL ? "smtps" : "smtp");
                transport.connect(host, user, password);
                transport.sendMessage(msg, msg.getAllRecipients());
            } catch (SendFailedException sfe) {
                if (!shouldIgnoreInvalidRecipients()) {
                    throw new BuildException(GENERIC_ERROR, sfe);
                } else if (sfe.getValidSentAddresses() == null
                           || sfe.getValidSentAddresses().length == 0) {
View Full Code Here

    }

    @Override
    public void send(final GmailMessage message) {
        if (message instanceof JavaMailGmailMessage) {
            Transport transport = null;
           
            try {
                final JavaMailGmailMessage msg = (JavaMailGmailMessage) message;
                transport = getGmailTransport();
                transport.sendMessage(
                        msg.getMessage(),
                        msg.getMessage().getAllRecipients());
            } catch (final Exception e) {
                throw new GmailException("Failed sending message: " + message, e);
            }
            finally{
                if(transport.isConnected())
                {
                    try {
                        transport.close();
                    } catch (final Exception e) {
                        LOG.warn("Cannot Close ImapGmailConnection : " + transport, e);
                    }
                }
            }
View Full Code Here

     *
     * @return Configured and ready for use Transport
     */
    public Transport getTransport() {
        try {
            final Transport transport = getSession().getTransport();
            transport.addConnectionListener(new ImapConnectionHandler(
                    new ConnectionInfo(loginCredentials.getUsername(),
                    gmailSmtpHost,
                    gmailSmtpPort)));
            transport.connect(loginCredentials.getUsername(),
                    new String(loginCredentials.getPasword()));
            return transport;
        } catch (final Exception e) {
            throw new GmailException("ImapGmailClient requires ImapGmailConnection!");
        }
View Full Code Here

                    .toString(isStartTls()));

            // Open the JavaMail session
            final Session session = Session.getDefaultInstance(props);
            session.setDebug(isDebug());
            final Transport tr = session.getTransport(transport);

            if (tr != null) {
                // Check if authentication is needed
                if (authenticate) {
                    tr.connect(smtpHost, getLogin(request),
                            getPassword(request));
                } else {
                    tr.connect();
                }

                // Actually send the message
                if (tr.isConnected()) {
                    getLogger()
                            .info(
                                    "JavaMail client connection successfully established. Attempting to send the message");

                    // Create the JavaMail message
                    final Message msg = createMessage(request.getEntity(),
                            session);

                    // Send the message
                    tr.sendMessage(msg, msg.getAllRecipients());
                    tr.close();

                    getLogger().info(
                            "JavaMail client successfully sent the message.");
                }
            }
View Full Code Here

    if (message.getSize() > mailSize) {
      throw new AttachmentTooLargeException();
    }

    // 连接邮件服务器并发送邮件
    Transport transport = session.getTransport("smtp");
    transport.connect(server, user, password);
    transport.sendMessage(message, message.getAllRecipients());
    transport.close();
  }
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.