Package javax.mail

Examples of javax.mail.Message


    protected void assertMailboxReceivedMessages(String name) throws IOException, MessagingException {
        Mailbox mailbox = Mailbox.get(name);
        assertEquals(name + " should have received 1 mail", 1, mailbox.size());

        Message message = mailbox.get(0);
        assertNotNull(name + " should have received at least one mail!", message);
        logMessage(message);
    }
View Full Code Here


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

        session.setDebug(debug);

        // create a message
        Message msg = new MimeMessage(session);

        msg.setFrom(new InternetAddress(from));
        msg.setRecipients(Message.RecipientType.TO, address);
        msg.setSubject(subject);
        msg.setText(attText);
        Transport.send(msg);
    }
View Full Code Here

  public static void sendValidationMail(String email, String nickname) throws MessagingException, UnsupportedEncodingException {
    Properties props = new Properties();
    Session mailSession = Session.getInstance(props, null);
        String msgBody = "Click" + "<a href='http://stewiemaze.appspot.com/register-player.do/validate.do?nickname=" + nickname +"'>" +
            " Here</a> to validate you account";
        Message msg = new MimeMessage(mailSession);
        Multipart mp = new MimeMultipart();
        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setContent(msgBody, "text/html");
        mp.addBodyPart(htmlPart);
        msg.setContent(mp);
        msg.setFrom(new InternetAddress("admin@stewiemaze.appspotmail.com"));
        msg.addRecipient(Message.RecipientType.TO,
                         new InternetAddress(email, nickname));
        msg.setSubject("Account Activation");
        Transport.send(msg);
  }
View Full Code Here

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

    String msgBody = "Your record was beaten by " + nickname + ", who scored " + newScore;

    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress("admin@stewiemaze.appspotmail.com"));
    msg.addRecipient(Message.RecipientType.TO,
        new InternetAddress(email));
    msg.setSubject("Record beaten");
    msg.setText(msgBody);
    Transport.send(msg);
  }
View Full Code Here

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

        try {
            Message msg = new MimeMessage(session);
           
            msg.setFrom(new InternetAddress("bookings-email-archive@woodcraft.org.uk", "Woodcraft Folk Bookings"));
           // msg.setFrom(new InternetAddress("simon@simplesi.org", "CoCamp Bookings Admin"));
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail(), user.getName()));
            msg.addRecipient(Message.RecipientType.BCC, new InternetAddress("bookings-email-archive@woodcraft.org.uk", user.getName()));
            msg.setSubject(subject);
            msg.setText(body);
            Transport.send(msg);

        // FIXME: Exception handling cleanup
        } catch (AddressException e) {
            throw new RuntimeException(e);
View Full Code Here

          challenge);

      if (sendTest) {
        Session session = Session.getDefaultInstance(new Properties(),
            null);
        Message msg = null;
        try {
          InternetAddress appInternetAddress = new InternetAddress(
              TestMessageConstants.TESTS_EMAIL_ADDRESS,
              TestMessageConstants.TEST_MESSAGE_SENDER_NAME);

          Map<String, Object> params = Maps.newHashMap();
          params.put("challenge", newTest.getChallenge());
          params.put(
              "url",
              "http://"
                  + SystemProperty.applicationId.get()
                  + ".appspot.com/answerTest.jsp?emailAddress="
                  + account.getEmailAddress() + "&challenge="
                  + newTest.getChallenge());

          String content = TemplateManager.getInstance(context)
              .applyTemplate(TemplateType.TEST_MESSAGE, params);

          msg = new MimeMessage(session);
          msg.setFrom(appInternetAddress);
          msg.addRecipient(Message.RecipientType.TO,
              account.getInternetAddress());
          msg.setReplyTo(new InternetAddress[] { appInternetAddress });
          msg.addHeader(
              TestMessageConstants.SMTP_HEADER_ACCOUNT_IDENTIFIER,
              KeyFactory.keyToString(account.getIdentifier()));
          msg.addHeader(
              TestMessageConstants.SMTP_HEADER_TEST_IDENTIFIER,
              KeyFactory.keyToString(newTest.getIdentifier()));
          msg.setSubject("Test Message on "
              + DateFormat.getInstance()
                  .format(newTest.getDate()));
          msg.setContent(content, "text/plain");
          Transport.send(msg);
        } catch (Exception e) {
          /*
           * Remove the test that was not successfully sent
           */
 
View Full Code Here

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

      String notificationMailAddress = unverifiedAccount
          .getEmailAddress();
      Message msg = null;
      try {
        msg = new MimeMessage(session);
        msg.setFrom(appInternetAddress);
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
            notificationMailAddress));
        msg.setReplyTo(new InternetAddress[] { appInternetAddress });
        msg.setSubject("Confirm the registration of your account '"
            + unverifiedAccount.getEmailAddress()
            + "' to Test Message");
        msg.setContent(
            getConfirmationEmail(context, unverifiedAccount),
            "text/html");

        Transport.send(msg);
      } catch (Exception e) {
View Full Code Here

        org.apache.camel.Message in = exchange.getIn();
        assertNotNull("Should have headers", in.getHeaders());

        MailExchange mailExchange = (MailExchange) exchange;
        Message inMessage = mailExchange.getIn().getMessage();
        assertNotNull("In message has no JavaMail message!", inMessage);

        String text = in.getBody(String.class);
        assertEquals("mail body", body, text);

        String to = in.getHeader("TO", String.class);
        assertEquals("TO Header", "james@localhost, bar@localhost", to);

        Enumeration iter = inMessage.getAllHeaders();
        while (iter.hasMoreElements()) {
            Header header = (Header) iter.nextElement();
            String[] value = message.getHeader(header.getName());
            log.debug("Header: " + header.getName() + " has value: " + ObjectHelper.asString(value));
        }
View Full Code Here

    protected void assertMailboxReceivedMessages(String name) throws IOException, MessagingException {
        Mailbox mailbox = Mailbox.get(name);
        assertEquals(name + " should have received 1 mail", 1, mailbox.size());

        Message message = mailbox.get(0);
        assertNotNull(name + " should have received at least one mail!", message);
        assertEquals("hello world!", message.getContent());
        assertEquals("camel@localhost", message.getFrom()[0].toString());
        boolean found = false;
        for (Address adr : message.getRecipients(RecipientType.TO)) {
            if (name.equals(adr.toString())) {
                found = true;
            }
        }
        assertTrue("Should have found the recpient to in the mail: " + name, found);
View Full Code Here

        Mailbox.clearAll();

        template.sendBodyAndHeader("mailbox:foo", "Hello Mailbox", "to", "davsclaus@apache.org");

        Mailbox box = Mailbox.get("davsclaus@apache.org");
        Message msg = box.get(0);
        assertEquals("davsclaus@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
    }
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.