Package javax.mail

Examples of javax.mail.Message


                }
            };
        }//else: no authentication
        Session session = Session.getInstance(props, pa);
// — Tạo đối tượng message
        Message msg = new MimeMessage(session);
// — Set các field FROM và TO
        msg.setFrom(new InternetAddress("nguyenduong111090@gmail.com"));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
                to, false));

// — Set tiêu đề và body (nội dung thư) –
        msg.setSubject("Welcome to KSC Website !");
        msg.setText("Congratulation ! You have register success ");
// — Set header information
        msg.setHeader("X-Mailer", "KSC-Email");
        msg.setSentDate(new Date());
        msg.saveChanges();
// — Gởi tin nhắn
        Transport.send(msg);
// Thông báo khi gởi thư thành công
        messages.taoTB(FacesMessage.SEVERITY_INFO, "Send mail Successfull .", "Successfull");
        }
View Full Code Here


                }
            };
        }//else: no authentication
        Session session = Session.getInstance(props, pa);
// — Tạo đối tượng message
        Message msg = new MimeMessage(session);
// — Set các field FROM và TO
        msg.setFrom(new InternetAddress("nguyenduong111090@gmail.com"));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
                to, false));

// — Set tiêu đề và body (nội dung thư) –
        msg.setSubject("Welcome to KSC Website !");
        msg.setText("Congratulation ! You have register success ");
// — Set header information
        msg.setHeader("X-Mailer", "KSC-Email");
        msg.setSentDate(new Date());
        msg.saveChanges();
// — Gởi tin nhắn
        Transport.send(msg);
// Thông báo khi gởi thư thành công
        messages.taoTB(FacesMessage.SEVERITY_INFO, "Send mail Successful .", "Successful");
        }
View Full Code Here


  public boolean sendVerification(String recipient, String authKey) {

    try {
      Message msg = new MimeMessage(s);
      msg.setFrom(new InternetAddress("noreply@ubc-cc.appspotmail.com",
          "UBC Course Companion"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
          recipient, recipient));
      msg.setSubject("New account verification");
      String body = EmailUtils.getVerificationMessageBody(recipient, authKey);
      msg.setText(body);
      Transport.send(msg);

    } catch (AddressException e1) {
      e1.printStackTrace();
      return false;
View Full Code Here

  }

  public static boolean sendMessage(String recipient, String body) {

    try {
      Message msg = new MimeMessage(s);
      msg.setFrom(new InternetAddress("noreply@ubc-cc.appspotmail.com",
          "UBC Course Companion"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
          recipient, recipient));
      msg.setSubject("UBC Course Information Update Notification");
      msg.setText(body);
      Transport.send(msg);

    } catch (AddressException e1) {
      e1.printStackTrace();
      return false;
View Full Code Here

                }
            };
        }//else: no authentication
        Session session = Session.getInstance(props, pa);
// — Tạo đối tượng message
        Message msg = new MimeMessage(session);
// — Set các field FROM và TO
        msg.setFrom(new InternetAddress(from));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
                to, false));

// — Set tiêu đề và body (nội dung thư) –
        msg.setSubject(subject);
        msg.setText(body);
// — Set header information
        msg.setHeader("X-Mailer", "KSC-Email");
        msg.setSentDate(new Date());
        msg.saveChanges();
// — Gởi tin nhắn
        Transport.send(msg);
// Thông báo khi gởi thư thành công
        messages.taoTB(FacesMessage.SEVERITY_INFO, "Send mail Successfull .", "Successfull");
        }
View Full Code Here

            // update pending number of exchanges
            pendingExchanges = total - index - 1;

            // must use the original message in case we need to workaround a charset issue when extracting mail content
            final Message mail = exchange.getIn(MailMessage.class).getOriginalMessage();

            // add on completion to handle after work when the exchange is done
            exchange.addOnCompletion(new SynchronizationAdapter() {
                public void onComplete(Exchange exchange) {
                    processCommit(mail, exchange);
View Full Code Here

            // If the protocol is POP3, the message needs to be synced with the folder via the UID.
            // Otherwise setting the DELETE/SEEN flag won't delete the message.
            String uid = (String) exchange.removeProperty(POP3_UID);
            if (uid != null) {
                int count = folder.getMessageCount();
                Message found = null;
                LOG.trace("Looking for POP3Message with UID {} from folder with {} mails", uid, count);
                for (int i = 1; i <= count; ++i) {
                    Message msg = folder.getMessage(i);
                    if (uid.equals(generatePop3Uid(msg))) {
                        LOG.debug("Found POP3Message with UID {} from folder with {} mails", uid, count);
                        found = msg;
                        break;
                    }
View Full Code Here

            }
        );
      
        session.setDebug(debug);
      
        Message msg = new MimeMessage(session);
        InternetAddress addressFrom = new InternetAddress(from);
        msg.setFrom(addressFrom);
        msg.setReplyTo(new Address[]{addressFrom});
      
        InternetAddress[] addressTo = new InternetAddress[recipients.length];
        for (int i = 0; i < recipients.length; i++) {
            addressTo[i] = new InternetAddress(recipients[i]);
        }
        //msg.setRecipients(Message.RecipientType.BCC, addressTo);
  
        MimeMultipart multipart = new MimeMultipart("alternative");
       
        if(attachmentURL!=null) {
          MimeBodyPart filePart = new MimeBodyPart();
          filePart.setFileName( attachmentFileName );
         
      URL url = new URL(attachmentURL);
      URLConnection connection = url.openConnection();
      connection.setRequestProperty( "User-Agent","OpenForum");
         
          ByteArrayDataSource ds = new ByteArrayDataSource(connection.getInputStream(), attachmentMimeType);
          filePart.setDataHandler(new DataHandler(ds));
          multipart.addBodyPart(filePart);
        }
       
        MimeBodyPart textPart = new MimeBodyPart();
        textPart.setContent(textMessage, "text/plain");
        multipart.addBodyPart(textPart);
       
        if(htmlMessage!=null) {
          MimeBodyPart htmlPart = new MimeBodyPart();
          String htmlData = htmlMessage;
          htmlPart.setContent(htmlData, "text/html");
          multipart.addBodyPart(htmlPart);
        }
       
        // 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();
View Full Code Here

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

      System.out.println(email + name + subject + content + "sayavn2013@gmail.com");
      try {
        Message msg = new MimeMessage(session);
        msg.setFrom(
          new InternetAddress(email,
          name));
        msg.addRecipient(Message.RecipientType.TO,
          new InternetAddress("sayavn2013@gmail.com", "Saya"));
        msg.setSubject(subject);
        msg.setText(content);
        Transport.send(msg);
      }
      catch (AddressException e) {
        result = Boolean.valueOf(false);
      } catch (MessagingException e) {
View Full Code Here

        List<InternetAddress> recipients = new ArrayList<InternetAddress>();
        recipients.add(recipient);
        InternetAddress replyTo = null;
        String subject = "Subject";
        String plaintext = "Plaintext";
        Message message = new GaeEmailUtils().createPlaintextMessage(sender, recipients, replyTo, subject, plaintext);
        assertNotNull(message);
        assertEquals(1, message.getReplyTo().length);
        assertEquals(sender, message.getReplyTo()[0]);
        assertEquals(1, message.getFrom().length);
        assertEquals(sender, message.getFrom()[0]);
        assertNull(message.getRecipients(RecipientType.CC));
        assertNull(message.getRecipients(RecipientType.BCC));
        assertEquals(1, message.getRecipients(RecipientType.TO).length);
        assertEquals(recipient, message.getRecipients(RecipientType.TO)[0]);
        assertEquals("text/plain", message.getContentType());
        assertEquals(plaintext, message.getContent());
    }
View Full Code Here

TOP

Related Classes of javax.mail.Message

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.