Package javax.mail

Examples of javax.mail.Session$ProviderInfo


   * @throws UnsupportedEncodingException
   */
  public static void main(String[] args) throws MessagingException, TextParseException, UnsupportedEncodingException {
    for(int ai=0;ai<args.length;ai++){
      String mailaddr = args[ai];
      Session ssn = initMailSession();
      MimeMessage mailMessage = new MimeMessage(ssn);
      mailMessage.setSubject("Hello MAIL");
      mailMessage.setSentDate(new Date());
      //Properties props = ssn.getProperties();
          //props.put("mail.smtp.from", "<>");
 
          Multipart multipart = new MimeMultipart("related");
      MimeBodyPart messageBodyPart = new MimeBodyPart();
          messageBodyPart.setText("Welcome to JavaMail.");
          multipart.addBodyPart(messageBodyPart);
          mailMessage.setContent(multipart);
          mailMessage.setFrom(new InternetAddress("javayou@gmail.com","Winter Lau"));
         
          String mail_postfix = mailaddr.substring(mailaddr.indexOf('@')+1);
          //System.out.println("mail postfix is " + mail_postfix);
          Lookup lookup = new Lookup(mail_postfix, Type.MX);
          lookup.run();
      if (lookup.getResult() != Lookup.SUCCESSFUL){
        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);
View Full Code Here


        Properties props = (Properties) System.getProperties().clone();
        props.put("mail.smtp.host", smtp);
        LogOutputStream logStream = new LogOutputStream(log, LogOutputStream.LEVEL_DEBUG);
        PrintStream debugOut = new PrintStream(logStream, true);

        Session session = Session.getDefaultInstance(props);
        session.setDebug(true);
        session.setDebugOut(debugOut);

        MimeMessage message = createMimeMessage(session, mailMessage);
        log.debug("Sending message");
        Transport.send(message);
    }
View Full Code Here

        MailcapCommandMap mailcap = (MailcapCommandMap) MailcapCommandMap.getDefaultCommandMap();
        mailcap.addMailcap( "text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain" );

        System.out.println( connection );
        Session session = Session.getInstance( connection,
                                               null );

        // Define message
        MimeMessage message = new MimeMessage( session );
        message.setHeader( "Content-Class",
View Full Code Here

            Properties props = new Properties();
            if ( mailhost != null && mailhost.trim().length() > 0 ) props.setProperty( "mail.smtp.host", mailhost );
            if ( connection.getPort() != null && connection.getPort().trim().length() > 0 ) {
                props.setProperty( "mail.smtp.port", connection.getPort() );               
            }              
            Session session = Session.getInstance( props, null );
            session.setDebug( debug );
           
            // construct the message
            Message msg = new MimeMessage( session );
           
            msg.setFrom( new InternetAddress( from ) );
            msg.setReplyTo( new InternetAddress[] {  new InternetAddress( replyTo ) }  );
           
            for ( Recipient recipient : message.getRecipients().getRecipients() ) {
                RecipientType type = null;
                if ( "To".equals( recipient.getType() ) ) {
                    type = Message.RecipientType.TO;
                } else if ( "Cc".equals( recipient.getType() ) ) {
                    type = Message.RecipientType.CC;
                } else if ( "Bcc".equals( recipient.getType() ) ) {
                    type = Message.RecipientType.BCC;
                } else {
                    throw new RuntimeException( "Unable to determine recipient type" );
                }

                msg.addRecipients( type, InternetAddress.parse( recipient.getEmail(), false ) );
            }
            msg.setSubject( subject );
            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 );
View Full Code Here

        throws Exception
    {
        Debug.print( "MailerMDB.send(" + to + "," + subject + ",...)" );

        InitialContext     ic = new InitialContext(  );
        Session            session = ( Session ) ic.lookup( JNDINames.MAIL_SESSION );
        javax.mail.Message msg = new MimeMessage( session );

        msg.setFrom(  );
        msg.setRecipients( javax.mail.Message.RecipientType.TO, InternetAddress.parse( to, false ) );
        msg.setSubject( subject );
View Full Code Here

        throws NamingException,
                   AddressException,
                   MessagingException
    {
        InitialContext     ic = new InitialContext(  );
        Session            session = ( Session ) ic.lookup( MAIL_SESSION );
        javax.mail.Message msg = new MimeMessage( session );

        msg.setFrom(  );
        msg.setRecipients( javax.mail.Message.RecipientType.TO, InternetAddress.parse( to, false ) );
        msg.setSubject( subject );
View Full Code Here

                    this.getSmtpPassword());
      props.put("mail.smtp.user", this.getSmtpUsername());
      props.put("mail.smtp.auth", "true");
    }
   
    Session session = Session.getInstance(props, auth);

    session.setDebug(true);

    MimeMessage msg = new MimeMessage(session);

    try
    {
View Full Code Here

System.out.println("  !! being used in SyncMailEJB.addEmail() !!\n");
System.out.println("  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
System.out.println("\n\n\n\n");
      props.put("mail.smtp.host","x");
// DEBUG - THIS NEEDS TO BE FIXED! ^^^^^^^^^^^^^^^^^^^^^
      Session session = Session.getDefaultInstance(props, null);
     
      byte b[] = (byte[])messageMap.get("inputstream");
      InputStream fis = new ByteArrayInputStream( b );
     
      MimeMessage messagefile = new MimeMessage( session , fis );
View Full Code Here

        props.put("mail.smtp.host", mailmessage.getSmtpserver());
      }else{
        return(false);
      }

      Session session = Session.getDefaultInstance(props, null);

      MimeMessage message = new MimeMessage(session);

      ArrayList to = mailmessage.getTo();
      String arrayto[] = new String[to.size()];
View Full Code Here

      {
        props.put("mail.smtp.host", mailmessage.getSmtpserver());
      }else{
        return(false);
      }
      Session session = Session.getDefaultInstance(props, null);
      MimeMessage message = new MimeMessage(session);

      int accountid = mailmessage.getAccountID();

      ArrayList bcc = mailmessage.getBcc();
View Full Code Here

TOP

Related Classes of javax.mail.Session$ProviderInfo

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.