Package com.sun.mail.smtp

Examples of com.sun.mail.smtp.SMTPTransport


        boolean isConnected = false;
       
        isConnected = transport.isConnected();
        if (isConnected)
        {
            SMTPTransport smtpTransport = (SMTPTransport) transport;
           
            String lastServerResponse = smtpTransport.getLastServerResponse();
            if (lastServerResponse.startsWith("250") == false)
            {
                isConnected = false;
                try
                {
                    smtpTransport.close();
                }
                catch (MessagingException me)
                {
                    if (logger.isInfoEnabled())
                    {
View Full Code Here


        msg.setFrom(addressFrom);
        InternetAddress addressTo = new InternetAddress(recipient);
        msg.setRecipient(Message.RecipientType.TO, addressTo);
        msg.setSubject(subject);
        msg.setContent(message, "text/plain");
        SMTPTransport t = (SMTPTransport) session.getTransport("smtps");
        t.connect(mailhost, authUsername, authPassword);
        logger.debug("smtps: connected to " + mailhost);
        t.sendMessage(msg, msg.getAllRecipients());
        t.close();
        logger.info("mail send to " + recipient);
      }
    } catch (NoSuchProviderException e) {
      e.printStackTrace();
    } catch (SendFailedException e) {
View Full Code Here

                msg.setSubject(subject);
                msg.setSentDate(new Date());
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
                    smtpTrans = new SMTPTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                }
                smtpTrans.connect();
                smtpTrans.sendMessage(msg, msg.getAllRecipients());
                smtpTrans.close();
            }
        }
View Full Code Here

    msg.setHeader("X-Mailer", mailer);
    msg.setSentDate(new Date());

   
      SMTPTransport t = (SMTPTransport) session.getTransport(prot);
      try {
      t.connect(mailhost, user, password);
      t.sendMessage(msg, msg.getAllRecipients());
    }
    finally {
      System.out.println("Response: " + t.getLastServerResponse());
      t.close();
    }
  }
View Full Code Here

                            continue;
                        }
                        // if the transport is a SMTPTransport (from sun) some
                        // performance enhancement can be done.
                        if (transport instanceof SMTPTransport)  {
                            SMTPTransport smtpTransport = (SMTPTransport) transport;
                          
                            // if the message is alredy 8bit or binary and the
                            // server doesn't support the 8bit extension it has
                            // to be converted to 7bit. Javamail api doesn't perform
                            // that conversion, but it is required to be a
View Full Code Here

    final Session smtpSession,
    final Message message)
    throws OmhException {
   
    // Get the transport from the session.
    SMTPTransport transport;
    try {
      transport =
        (SMTPTransport) smtpSession.getTransport(MAIL_PROTOCOL);
    }
    catch(NoSuchProviderException e) {
      throw
        new OmhException(
          "There is no provider for " + MAIL_PROTOCOL + ".",
          e);
    }

    // Connect to the transport.
    try {
      transport.connect();
    }
    catch(MessagingException e) {
      throw new OmhException("Could not connect to the mail server.", e);
    }
   
    // Send the message.
    try {
      transport.sendMessage(message, message.getAllRecipients());
    }
    catch(SendFailedException e) {
      throw new OmhException("Failed to send the message.", e);
    }
    catch(MessagingException e) {
      throw
        new OmhException(
          "There was a problem while sending the message.",
          e);
    }
    finally {
      // Close the connection to the transport.
      try {
        transport.close();
      }
      catch(MessagingException e) {
        LOGGER
          .log(
            Level.WARNING,
View Full Code Here

            multipart.addBodyPart(attachmentBodyPart);
        }
      
        message.setContent(multipart);

        SMTPTransport smtp = (SMTPTransport)session.getTransport("smtps");

        String userName = config.getProperty("custom.userName");
        String password = config.getProperty("custom.password");
        
        smtp.connect("smtp.gmail.com", userName, password);
        smtp.sendMessage(message, message.getAllRecipients());     
        smtp.close();
    }
View Full Code Here

            multipart.addBodyPart(attachmentBodyPart);
        }
      
        message.setContent(multipart);

        SMTPTransport smtp = (SMTPTransport)session.getTransport("smtps");

        String userName = config.getProperty("custom.userName");
        String password = config.getProperty("custom.password");
        
        smtp.connect("smtp.gmail.com", userName, password);
        smtp.sendMessage(message, message.getAllRecipients());     
        smtp.close();
    }
View Full Code Here

                msg.setSubject(subject);
                msg.setSentDate(new Date());
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
                    smtpTrans = new SMTPTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                }
                sendMessage(smtpTrans, msg);
            }
        }
View Full Code Here

                msg.setSubject(subject);
                msg.setSentDate(new Date());
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
                    smtpTrans = new SMTPTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                }
                sendMessage(smtpTrans, msg);
            }
        }
View Full Code Here

TOP

Related Classes of com.sun.mail.smtp.SMTPTransport

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.