Package javax.mail.internet

Examples of javax.mail.internet.InternetAddress


            throw new RuntimeException("This mail sender is stopped");
        }
        try {
            MimeMessage mm = new MimeMessage(getSession());
            mm.setSubject(subject);
            mm.setFrom(new InternetAddress(from, fromPersonal));
            Address[] add = new Address[1];
            add[0] = new InternetAddress(replyTo);
            mm.setReplyTo(add);
            for (String sTo : to) {
                mm.addRecipient(RecipientType.TO, new InternetAddress(sTo));
            }
            mm.setContent(text, "text/plain");
            sendMail(mm);
        } catch (UnsupportedEncodingException ex) {
            throw new RuntimeException(ex);
View Full Code Here


                // Test the headers
               
                Assert.assertNotNull(renderedMessage);
                Assert.assertEquals(renderedMessage.getAllRecipients().length, 1);
                Assert.assertTrue(renderedMessage.getAllRecipients()[0] instanceof InternetAddress);
                InternetAddress to = (InternetAddress) renderedMessage.getAllRecipients()[0];
                Assert.assertEquals(to.getAddress(), "test@example.com");
                Assert.assertEquals(to.getPersonal(), "Pete Muir");
                Assert.assertEquals(renderedMessage.getFrom().length, 1);
                Assert.assertTrue(renderedMessage.getFrom()[0] instanceof InternetAddress);
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "peter@example.com");
                Assert.assertEquals(from.getPersonal(), "Peter");
                Assert.assertEquals(renderedMessage.getSubject(), "Try out Seam!");
                Assert.assertNull(renderedMessage.getHeader("Precedence"));
                Assert.assertNull(renderedMessage.getHeader("X-Priority"));
                Assert.assertNull(renderedMessage.getHeader("Priority"));
                Assert.assertNull(renderedMessage.getHeader("Importance"));
View Full Code Here

            {
                MimeMessage renderedMessage = getRenderedMailMessage("/attachment.xhtml");
               
                // Test the headers
               
                InternetAddress to = (InternetAddress) renderedMessage.getAllRecipients()[0];
                Assert.assertEquals(to.getAddress(), "gavin@king.com");
                Assert.assertEquals(to.getPersonal(), "Gavin King");
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "do-not-reply@jboss.com");
                Assert.assertEquals(from.getPersonal(), "Seam");
                Assert.assertEquals(renderedMessage.getSubject(), "Try out Seam!");
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();               
   
                Assert.assertEquals(body.getCount(), 4); //3 Attachments and 1 MimeMultipart               
               
View Full Code Here

            {  
                MimeMessage renderedMessage = getRenderedMailMessage("/html.xhtml");
            
                // Test the standard headers
               
                InternetAddress to = (InternetAddress) renderedMessage.getAllRecipients()[0];
                Assert.assertEquals(to.getAddress(), "test@example.com");
                Assert.assertEquals(to.getPersonal(), "Pete Muir");
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "do-not-reply@jboss.com");
                Assert.assertEquals(from.getPersonal(), "Seam");
                Assert.assertEquals(renderedMessage.getSubject(), "Seam Mail");
               
                // Test the extra headers
               
                // Importance
View Full Code Here

            {  
                MimeMessage renderedMessage = getRenderedMailMessage("/plain.xhtml");
            
                // Test the standard headers
               
                InternetAddress to = (InternetAddress) renderedMessage.getAllRecipients()[0];
                Assert.assertEquals(to.getAddress(), "test@example.com");
                Assert.assertEquals(to.getPersonal(), "Pete Muir");
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "do-not-reply@jboss.com");
                Assert.assertEquals(from.getPersonal(), "Seam");
                Assert.assertEquals(renderedMessage.getReplyTo().length,  1);
                Assert.assertTrue(renderedMessage.getReplyTo()[0] instanceof InternetAddress);
                InternetAddress replyTo = (InternetAddress) renderedMessage.getReplyTo()[0];
                Assert.assertEquals(replyTo.getAddress(), "another.address@jboss.org");
                Assert.assertEquals(replyTo.getPersonal(), "JBoss");
                Assert.assertEquals(renderedMessage.getRecipients(CC).length, 1);
                Assert.assertTrue(renderedMessage.getRecipients(CC)[0] instanceof InternetAddress);
                InternetAddress cc = (InternetAddress) renderedMessage.getRecipients(CC)[0];
                Assert.assertEquals(cc.getAddress(), "test@example.com");
                Assert.assertEquals(cc.getPersonal(), "Pete Muir");
                Assert.assertEquals(renderedMessage.getRecipients(BCC).length, 1);
                Assert.assertTrue(renderedMessage.getRecipients(BCC)[0] instanceof InternetAddress);
                InternetAddress bcc = (InternetAddress) renderedMessage.getRecipients(CC)[0];
                Assert.assertEquals(bcc.getAddress(), "test@example.com");
                Assert.assertEquals(bcc.getPersonal(), "Pete Muir");
                Assert.assertEquals(renderedMessage.getHeader("Precedence")[0], "bulk");
                // Importance
                Assert.assertNotNull(renderedMessage.getHeader("X-Priority"));
                Assert.assertNotNull(renderedMessage.getHeader("Priority"));
                Assert.assertNotNull(renderedMessage.getHeader("Importance"));
View Full Code Here

            protected void invokeApplication() throws Exception
            {
                Contexts.getEventContext().set("name", "Pete\nMuir");  
                MimeMessage renderedMessage = getRenderedMailMessage("/org/jboss/seam/example/mail/test/sanitization.xhtml");
                Assert.assertEquals(renderedMessage.getSubject(), "Try out Seam!");
                InternetAddress to = (InternetAddress) renderedMessage.getAllRecipients()[0];
                Assert.assertEquals(to.getAddress(), "peter@email.tld");
                Assert.assertEquals(to.getPersonal(), "Pete");
                Assert.assertEquals(renderedMessage.getFrom().length, 1);
                Assert.assertTrue(renderedMessage.getFrom()[0] instanceof InternetAddress);
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "peter@example.com");
                Assert.assertEquals(from.getPersonal(), "Pete");
                Assert.assertNotNull(renderedMessage.getHeader("Pete"));
                Assert.assertEquals(renderedMessage.getHeader("Pete").length, 1);
                Assert.assertEquals(renderedMessage.getHeader("Pete")[0], "roll over");
            }
        }.run();
View Full Code Here

            {  
                MimeMessage renderedMessage = getRenderedMailMessage("/templating.xhtml");
            
                // Test the standard headers
               
                InternetAddress to = (InternetAddress) renderedMessage.getAllRecipients()[0];
                Assert.assertEquals(to.getAddress(), "test@example.com");
                Assert.assertEquals(to.getPersonal(), "Pete Muir");
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "do-not-reply@jboss.com");
                Assert.assertEquals(from.getPersonal(), "Seam");
                Assert.assertEquals(renderedMessage.getSubject(), "Templating with Seam Mail");
                Assert.assertNull(renderedMessage.getHeader("X-Priority"));
                Assert.assertNull(renderedMessage.getHeader("Priority"));
                Assert.assertNull(renderedMessage.getHeader("Importance"));
               
View Full Code Here

                DataSource ds = new ByteArrayDataSource(item.getData(), mimeType);
                attachment.setDataHandler(new DataHandler(ds));
                mp.addBodyPart(attachment);
            }
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(fromAddress, fromText));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress(toAddress, toAddress));
            msg.setSubject(subject, "UTF-8");
            msg.setContent(mp);
            Transport.send(msg);
            return null;
        } catch (AddressException e) {
View Full Code Here

         if (this.from == null || this.from.length() == 0) {
            throw new Exception(
               SOSClassUtil.getMethodName() + ": no sender specified.");
         }
          if ( this.fromName != null && this.fromName.length() > 0 ) {
            message.setFrom( new InternetAddress(this.from, this.fromName) );
         } else {
            message.setFrom( new InternetAddress(this.from) );
         }
         
          message.setSentDate( new Date() );
         

         if (this.replyTo != null && this.replyTo.length() > 0) {
            InternetAddress fromAddrs[] = new InternetAddress[1];
            fromAddrs[0] = new InternetAddress(this.replyTo);
            message.setReplyTo( fromAddrs );
         }


          if (!this.toList.isEmpty()) {
            InternetAddress toAddrs[] = new InternetAddress[toList.size()];
            int i = 0;          
          
            for (ListIterator e = this.toList.listIterator(); e.hasNext();) {
               t = e.next().toString();
               toAddrs[i++] = new InternetAddress(t);
            }

            message.setRecipients(MimeMessage.RecipientType.TO, toAddrs );
         }

        // if (!this.ccList.isEmpty()) { 
        // Sonst wirkt clearReceipients nicht.
            InternetAddress toAddrs[] = new InternetAddress[ccList.size()];
            int i = 0;          
            for (ListIterator e = this.ccList.listIterator(); e.hasNext();) {
               t = e.next().toString();
               toAddrs[i++] = new InternetAddress(t);
            }
            message.setRecipients(MimeMessage.RecipientType.CC, toAddrs );
        // }

        // if (!this.bccList.isEmpty()) {
            toAddrs = new InternetAddress[bccList.size()];
            i = 0;          
            for (ListIterator e = this.bccList.listIterator(); e.hasNext(); ) {
               t = e.next().toString();
               toAddrs[i++] = new InternetAddress(t);
            }
            message.setRecipients(MimeMessage.RecipientType.BCC, toAddrs );
         //}

         if (this.subject != null) {
View Full Code Here

          this.reportError( bReq, cW,
            "Could not retrieve " +itemName+ " #" + id );
          }
        else
          {
          InternetAddress addr = null;
          Vector vAddr = new Vector(2);

          int userId = 0;
          Person p = null;
          if ( userIdStr != null )
            {
            userId = Integer.parseInt( userIdStr );
            }

          if ( userId != 0 )
            {
            p = Person.getPerson( userId );
            if ( p == null )
              {
              throw new DBIException
                ( "Could not find email user #"
                  + userId );
              }
            }

          if ( p != null )
            {
            vAddr.addElement
              ( new InternetAddress
                ( p.getEmail(), p.getName() ) );
            }

          if ( otherStr != null && otherStr.length() > 0 )
            {
            InternetAddress[] oa =
              InternetAddress.parse( otherStr );

            if ( oa != null && oa.length > 0 )
              {
              for ( int i = 0 ; i < oa.length ; ++i )
                {
                vAddr.addElement( oa[i] );
                }
              }
            }

          InternetAddress fromAddr = null;
          int senderId = this.getUserId( bReq );
          if ( senderId != 0 )
            {
            p = Person.getPerson( senderId );
            if ( p != null )
              {
              fromAddr = new InternetAddress
                ( p.getEmail(), p.getName() );
              }
            }

          Description desc = isBug
View Full Code Here

TOP

Related Classes of javax.mail.internet.InternetAddress

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.