Package at.molindo.notify.model

Examples of at.molindo.notify.model.Message


  }

  @Override
  public synchronized void send(Dispatch dispatch) throws MailException {

    Message message = dispatch.getMessage();

    String recipient = dispatch.getParams().get(MailChannel.RECIPIENT);
    String recipientName = dispatch.getParams().get(MailChannel.RECIPIENT_NAME);
    String subject = message.getSubject();

    try {
      MimeMessage mm = new MimeMessage(getSmtpSession(recipient)) {
        @Override
        protected void updateMessageID() throws MessagingException {
          String domain = _from.getAddress();
          int idx = _from.getAddress().indexOf('@');
          if (idx >= 0) {
            domain = domain.substring(idx + 1);
          }
          setHeader("Message-ID", "<" + UUID.randomUUID() + "@" + domain + ">");
        }
      };
      mm.setFrom(_from);
      mm.setSender(_from);

      InternetAddress replyTo = getReplyTo();
      if (replyTo != null) {
        mm.setReplyTo(new Address[] { replyTo });
      }
      mm.setHeader("X-Mailer", "molindo-notify");
      mm.setSentDate(new Date());

      mm.setRecipient(RecipientType.TO,
          new InternetAddress(recipient, recipientName, CharsetUtils.UTF_8.displayName()));
      mm.setSubject(subject, CharsetUtils.UTF_8.displayName());

      if (_format == Format.HTML) {
        if (message.getType() == Type.TEXT) {
          throw new MailException("can't send HTML mail from TEXT message", false);
        }
        mm.setText(message.getHtml(), CharsetUtils.UTF_8.displayName(), "html");
      } else if (_format == Format.TEXT || _format == Format.MULTI && message.getType() == Type.TEXT) {
        mm.setText(message.getText(), CharsetUtils.UTF_8.displayName());
      } else if (_format == Format.MULTI) {
        MimeBodyPart html = new MimeBodyPart();
        html.setText(message.getHtml(), CharsetUtils.UTF_8.displayName(), "html");

        MimeBodyPart text = new MimeBodyPart();
        text.setText(message.getText(), CharsetUtils.UTF_8.displayName());

        /*
         * The formats are ordered by how faithful they are to the
         * original, with the least faithful first and the most faithful
         * last. (http://en.wikipedia.org/wiki/MIME#Alternative)
         */
        MimeMultipart mmp = new MimeMultipart();
        mmp.setSubType("alternative");

        mmp.addBodyPart(text);
        mmp.addBodyPart(html);

        mm.setContent(mmp);
      } else {
        throw new NotifyRuntimeException("unexpected format (" + _format + ") or type (" + message.getType()
            + ")");
      }

      send(mm);

View Full Code Here


  private IParams _masterParams;

  @Override
  public Message render(String key, Version version, IParams params) throws RenderException {

    Message mRaw = _renderService.render(key, version, params);

    Params masterParams = new Params();
    if (_masterParams != null) {
      masterParams.setAll(_masterParams);
    }
    masterParams.set(getMasterTemplateMessageParam(), mRaw);

    Boolean renderMaster = params.get(INotifyService.RENDER_MASTER_TEMPLATE);

    Message m;
    if (!Boolean.FALSE.equals(renderMaster)) {
      m = _renderService.render(_masterTemplateKey, version, masterParams);
      if (StringUtils.empty(m.getSubject()) && !StringUtils.empty(mRaw.getSubject())) {
        m.setSubject(mRaw.getSubject());
      }
    } else {
      m = mRaw;
    }
    return m;
View Full Code Here

TOP

Related Classes of at.molindo.notify.model.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.