Package javax.mail

Examples of javax.mail.Message


   * editor for it.  If
   */
  public void openWindowAsNew(boolean removeProxy) {
    try {
      // first create the NewMessageProxy from this MessageProxy.
      Message newMessage = new MimeMessage((MimeMessage)getMessageInfo().getMessage());
      NewMessageInfo nmi = new NewMessageInfo(newMessage);
      NewMessageProxy nmp = new NewMessageProxy(nmi);
      nmi.setDefaultProfile(getDefaultProfile());

      final MessageUI nmu = Pooka.getUIFactory().createMessageUI(nmp, getMessageUI());
View Full Code Here


            }
          }
      }
     
      // Try the sender's private key
      Message msg = this.getMessageInfo().getMessage();
      Address[] senders = msg.getFrom();
      Address[] receivers = msg.getAllRecipients();
     
      // Try first the recipients' private key
      for (int i = 0; i < senders.length + receivers.length; i++) {
        Address address = (i < senders.length)?
            senders[i] : receivers[i-senders.length];
View Full Code Here

        session.setDebug(debug);

        try
        {
            // Create a message.
            Message msg = new MimeMessage(session);

            // Set the email address that the message is from.
            msg.setFrom(from);

            // Set the email addresses that the message is to.
            msg.setRecipients(Message.RecipientType.TO, to);

            // Set the email addresses that will be carbon-copied.
            if (cc != null)
            {
                msg.setRecipients(Message.RecipientType.CC, cc);
            }

            // Set the email addresses that will be
            // blind-carbon-copied.
            if (bcc != null)
            {
                msg.setRecipients(Message.RecipientType.BCC, bcc);
            }

            // Set the email addresses that reply-to messages are
            // sent.
            if (replyTo != null)
            {
                msg.setReplyTo(replyTo);
            }

            // Set the subject of the email message.
            msg.setSubject(subject);

            // Set the body of the message.  If the desired charset is
            // known, use setText(text, charset).
            msg.setText(body);

            // msg.addHeader("X-Mailer", "com.i2a.util.mail.Sendmail");

            if (headers != null)
            {
                Enumeration e = headers.keys();
                while (e.hasMoreElements())
                {
                    String name = (String) e.nextElement();
                    String value = (String) headers.get(name);
                    msg.addHeader(name, value);
                }
            }

            // Send the message.
            Transport.send(msg);
View Full Code Here

        doEventTests(TransportEvent.MESSAGE_PARTIALLY_DELIVERED);
        doEventTests(TransportEvent.MESSAGE_NOT_DELIVERED);
    }
    private void doEventTests(int type) throws AddressException {
        Folder folder = TestData.getTestFolder();
        Message message = TestData.getMessage();
        Transport transport = TestData.getTestTransport();
        Address[] sent = new Address[] { new InternetAddress("alex@here.com")};
        Address[] empty = new Address[0];
        TransportEvent event =
            new TransportEvent(transport, type, sent, empty, empty, message);
View Full Code Here

     * Runs through the array of messages and appends them onto the folder using {@link #add(Message)}.
     * @param messages the array of messages to add.
     */
    public void appendMessages(Message[] messages) throws MessagingException {
        for (int i = 0; i < messages.length; i++) {
            Message message = messages[i];
            _messages.add(message);
        }
    }
View Full Code Here

     */
    public Message[] expunge() throws MessagingException {
        Iterator it = _messages.iterator();
        List result = new LinkedList();
        while (it.hasNext()) {
            Message message = (Message) it.next();
            if (message.isSet(Flags.Flag.DELETED)) {
                it.remove();
                result.add(message);
            }
        }
        // run through and renumber the messages
        for (int i = 0; i < _messages.size(); i++) {
            Message message = (Message) _messages.get(i);
            doRenumberMessageTo(message, i);
            //            message.setMessageNumber(i);
        }
        return (Message[]) result.toArray(MESSAGE_ARRAY);
    }
View Full Code Here

        if(mailProvider == null) {
            return;
        }
       
        Session session = mailProvider.getSession();
        Message message = new MimeMessage(session);
       
        // n.b. any default from address is expected to be determined by caller.
        if (! StringUtils.isEmpty(from)) {
            InternetAddress sentFrom = new InternetAddress(from);
            message.setFrom(sentFrom);
            if (log.isDebugEnabled()) log.debug("e-mail from: " + sentFrom);
        }
       
        if (to!=null) {
            InternetAddress[] sendTo = new InternetAddress[to.length];
           
            for (int i = 0; i < to.length; i++) {
                sendTo[i] = new InternetAddress(to[i]);
                if (log.isDebugEnabled()) log.debug("sending e-mail to: " + to[i]);
            }
            message.setRecipients(Message.RecipientType.TO, sendTo);
        }
       
        if (cc != null) {
            InternetAddress[] copyTo = new InternetAddress[cc.length];
           
            for (int i = 0; i < cc.length; i++) {
                copyTo[i] = new InternetAddress(cc[i]);
                if (log.isDebugEnabled()) log.debug("copying e-mail to: " + cc[i]);
            }
            message.setRecipients(Message.RecipientType.CC, copyTo);
        }
       
        if (bcc != null) {
            InternetAddress[] copyTo = new InternetAddress[bcc.length];
           
            for (int i = 0; i < bcc.length; i++) {
                copyTo[i] = new InternetAddress(bcc[i]);
                if (log.isDebugEnabled()) log.debug("blind copying e-mail to: " + bcc[i]);
            }
            message.setRecipients(Message.RecipientType.BCC, copyTo);
        }
        message.setSubject((subject == null) ? "(no subject)" : subject);
        message.setContent(content, mimeType);
        message.setSentDate(new java.util.Date());
       
        // First collect all the addresses together.
        Address[] remainingAddresses = message.getAllRecipients();
        int nAddresses = remainingAddresses.length;
        boolean bFailedToSome = false;
       
        SendFailedException sendex = new SendFailedException("Unable to send message to some recipients");
       
View Full Code Here

    properties.put("mail.smtp.host", "smtp.163.com");// 设置发信邮箱的smtp地址
    properties.setProperty("mail.smtp.auth", "true"); // 验证
    Authenticator auth = new AjavaAuthenticator(emailName,
        emailPassword); // 使用验证,创建一个Authenticator
    Session session = Session.getDefaultInstance(properties, auth);// 根据Properties,Authenticator创建Session
    Message message = new MimeMessage(session);// Message存储发送的电子邮件信息
    message.setFrom(new InternetAddress(fromEmail));
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(
        toEmail));// 设置收信邮箱
    // 指定邮箱内容及ContentType和编码方式
    message.setContent(centent, "text/html;charset=utf-8");
    message.setSubject(title);// 设置主题
    message.setSentDate(new Date());// 设置发信时间
    Transport.send(message);// 发送

  }
View Full Code Here

        j.assertBuildStatusSuccess(b);
       
        Mailbox mbox = Mailbox.get("mickey@disney.com");
        assertEquals("Should have an email from success", 1, mbox.size());
       
        Message msg = mbox.get(0);
        assertTrue("Message should be multipart", msg instanceof MimeMessage);
        assertTrue("Content should be a MimeMultipart", msg.getContent() instanceof MimeMultipart);
       
        MimeMultipart part = (MimeMultipart)msg.getContent();
       
        assertEquals("Should have two body items (message + attachment)", 2, part.getCount());
       
        BodyPart attach = part.getBodyPart(1);
        assertTrue("There should be a PDF named \"test.pdf\" attached", "test.pdf".equalsIgnoreCase(attach.getFileName()));       
View Full Code Here

        j.assertBuildStatusSuccess(b);
       
        Mailbox mbox = Mailbox.get("mickey@disney.com");
        assertEquals("Should have an email from success", 1, mbox.size());
       
        Message msg = mbox.get(0);
        assertTrue("Message should be multipart", msg instanceof MimeMessage);
        assertTrue("Content should be a MimeMultipart", msg.getContent() instanceof MimeMultipart);
       
        MimeMultipart part = (MimeMultipart)msg.getContent();
       
        assertEquals("Should have two body items (message + attachment)", 2, part.getCount());
       
        BodyPart attach = part.getBodyPart(1);
        assertTrue("There should be a PDF named \"test.pdf\" attached", "test.pdf".equalsIgnoreCase(attach.getFileName()));       
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.