Package javax.mail

Examples of javax.mail.Message


        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


    //
    Session session = Session.getDefaultInstance(props, null);
    //
    // Erzeugen einer MimeMessage:
    //
    Message msg = new MimeMessage(session);
    //
    // Erzeugen der Absender-Adresse der Message:
    //
    InternetAddress fromAddress = new InternetAddress(from);
    msg.setFrom(fromAddress);
    //
    // Erzeugen der Empf�nger-Adresse der Message:
    //
    int max = to.length;
    InternetAddress[] toAddress = new InternetAddress[max];
    for (int i = 0; i < max; i++) {
      toAddress[i] = new InternetAddress(to[i]);
    }
    msg.setRecipients(Message.RecipientType.TO, toAddress);
    //
    // Setzen des Subjects der Message:
    //
    msg.setSubject(subject);

    // BURMEBJ003A begin
    if (attachements == null) {
      //
      // Setzen des Message-Contents:
      //
      msg.setContent(msgText, "text/plain; charset=ISO-8859-1");
    }
    // BURMEBJ003A end
    else {
      // BURMEBJ003 moved begin
      //
      // Erzeugen eines MimeMultipart:
      //
      MimeMultipart mp = new MimeMultipart();
      //
      // Anhängen eines MimeBodyParts für den einleitenden Text:
      //
      MimeBodyPart text = new MimeBodyPart();
      text.setDisposition(Part.INLINE);
      text.setContent(msgText, "text/plain; charset=ISO-8859-1");
      mp.addBodyPart(text);
      //
      // Anhängen der Attachements:
      //
      // BURMEBJ003 moved end
      // @BURMEBJ002A begin
      int numberOfFileNames = 0;
      if (fileNames != null) {
        numberOfFileNames = fileNames.length;
      }
      // @BURMEBJ002A end

      for (int i = 0; i < attachements.length; i++) {
        MimeBodyPart file_part = new MimeBodyPart();
        java.io.File file = attachements[i];
        FileDataSource fds = new FileDataSource(file);
        DataHandler dh = new DataHandler(fds);
        // @BURMEBJ002M begin
        String fileName = file.getName();
        if (i < numberOfFileNames && fileNames[i] != null) {
          fileName = fileNames[i];
        }
        file_part.setFileName(fileName);
        // @BURMEBJ002M end
        file_part.setDisposition(Part.ATTACHMENT);
        file_part.setDescription("Attached file: " + file.getName());
        file_part.setDataHandler(dh);
        mp.addBodyPart(file_part);
      }
      msg.setContent(mp);
    }
    //
    // Abschicken der Message:
    //
    Transport.send(msg);
View Full Code Here

    try {
      folder = store.getFolder("Inbox");

      fld=(IMAPFolder)folder;
      fld.open(Folder.READ_ONLY);
      Message message=fld.getMessage(max_uid);
      gm.message_id=max_uid;
      gm.subject=message.getSubject();
      try{
       
        gm.message_body=(String) message.getContent();
      }catch(ClassCastException e){
        gm.message_body="";
        e.printStackTrace();
      }
      gm.sender=message.getFrom()[0].toString();

      fld.close(false);
    } catch (MessagingException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
View Full Code Here

  @Override
  public void MessagesReceived(Collection<InboundMessage> msgList) throws Exception
  {
    for (InboundMessage im : msgList)
    {
      Message msg = new MimeMessage(this.mailSession);
      msg.setFrom();
      msg.addRecipient(RecipientType.TO, new InternetAddress(getProperty("to")));
      msg.setSubject(updateTemplateString(this.messageSubject, im));
      if (this.messageBody != null)
      {
        msg.setText(updateTemplateString(this.messageBody, im));
      }
      else
      {
        msg.setText(im.toString());
      }
      msg.setSentDate(im.getDate());
      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(from, fromAlias));
              msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to, toAlias));
              if(subject!=null) msg.setSubject(subject);
              if(body!=null) msg.setText(body);
              Transport.send(msg);
     
          } catch (AddressException e) {
              // ...
          } catch (MessagingException e) {
View Full Code Here

    String objet = req.getParameter("objet");
    String message = req.getParameter("message");
    String addrUsr = req.getParameter("addrusr");

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress("julien.plagnes@gmail.com",
          "Julien & Co"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
          addrUsr, "User"));
      msg.setSubject(objet);
      msg.setText(message);
      Transport.send(msg);

      resp.sendRedirect("/");
    } catch (AddressException e) {
      // ...
View Full Code Here

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

      try {
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(adminAddress, adminName));
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient, "Mr. User"));
        msg.setSubject(subject);
        msg.setText(messageBody);
        Transport.send(msg);
        sendResult = "Message sent OK";

      } catch (AddressException e) {
        sendResult = e.getMessage();
View Full Code Here

  }

  public String send()
  {
    Session session = _getSession();
    Message msg = _setupMessage(new MimeMessage(session));
    if (msg == null)
    {
      _LOG.info("Could not create Message object for " + getSubject());
      return null;
    }
View Full Code Here

  public String saveAsDraft()
  {
    _LOG.info("Beginning send of message " + getSubject());

    Session session = _getSession();
    Message msg = _setupMessage(new MimeMessage(session));
    if (msg == null)
    {
      _LOG.info("Could not create Message object for " + getSubject());
      return null;
    }
View Full Code Here

    MessageData message =
      (MessageData) afContext.getPageFlowScope().get("message");

    if (message == null) return;
    Message msg = message.getMessage();

    try
    {
        msg.getFolder().open(Folder.READ_ONLY);
        Message replyMessage = msg.reply(replyToAll);

        setSubject(replyMessage.getSubject());
        Address[] replyToAddresses = replyMessage.getAllRecipients();
        setTo(_getAddressString(replyToAddresses));

    }
    catch (MessagingException e)
    {
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.