Examples of MailService


Examples of com.alibaba.citrus.service.mail.MailService

            return mailRef;
        }

        @Override
        protected void render(Part mailPart, String fileName) {
            MailService mailService = getMailBuilder().getMailService();

            if (mailService == null) {
                throw new MailBuilderException("Could not find mail \"" + mailRef + "\": no MailService");
            }

            MailBuilder mailBuilder;

            try {
                mailBuilder = mailService.getMailBuilder(mailRef);
            } catch (MailNotFoundException e) {
                throw new MailBuilderException("Could not find mail \"" + mailRef + "\"", e);
            }

            Message mail = mailBuilder.getMessage(getMailBuilder().getSession());
View Full Code Here

Examples of com.alibaba.citrus.service.mail.MailService

        }

        MailBuilder builder = getMailBuilder(false);

        if (builder != null) {
            MailService mailService = builder.getMailService();

            if (mailService != null) {
                return mailService.getService(serviceType, defaultId);
            }
        }

        return null;
    }
View Full Code Here

Examples of com.gitblit.service.MailService

  private final MailService mailService;

  public NotificationManager(IStoredSettings settings) {
    this.settings = settings;
    this.mailService = new MailService(settings);
  }
View Full Code Here

Examples of com.gitblit.service.MailService

    File file = new File(folder, "gitblit.properties");
    if (!file.exists()) {
      return null;
    }
    gitblitSettings = new FileSettings(file.getAbsolutePath());
    mail = new MailService(gitblitSettings);
    String us = gitblitSettings.getString(Keys.realm.userService, "${baseFolder}/users.conf");
    String ext = us.substring(us.lastIndexOf(".") + 1).toLowerCase();
    IUserService service = null;
    if (!ext.equals("conf") && !ext.equals("properties") && ext.contains("userservice")) {
      String realm = ext.substring(0, ext.indexOf("userservice"));
View Full Code Here

Examples of com.gitblit.service.MailService

  private final MailService mailService;

  public NotificationManager(IStoredSettings settings) {
    this.settings = settings;
    this.mailService = new MailService(settings);
  }
View Full Code Here

Examples of com.gitblit.service.MailService

public class MailTest extends GitblitUnitTest {

  @Test
  public void testSendMail() throws Exception {
    FileSettings settings = new FileSettings("mailtest.properties");
    MailService mail = new MailService(settings);
    Mailing mailing = Mailing.newPlain();
    mailing.setRecipients(settings.getStrings(Keys.mail.adminAddresses));
    Message message = mail.createMessage(mailing);
    message.setSubject("Test");
    message.setText("Lägger till andra stycket i ny fil. UTF-8 encoded");
    mail.queue(message);
    mail.run();

    assertTrue("mail queue is not empty!", mail.hasEmptyQueue());
  }
View Full Code Here

Examples of com.google.appengine.api.mail.MailService

  /** {@inheritDoc} */
  @Override
  public void sendMessage(Message message, Address[] addresses)
      throws MessagingException {
    MailService service = MailServiceFactory.getMailService();
    MailService.Message msg = new MailService.Message();

    String sender = null;
    if (message instanceof MimeMessage) {
      Address senderAddr = ((MimeMessage) message).getSender();
      if (senderAddr != null) {
        sender = senderAddr.toString();
      }
    }
    if (sender == null && message.getFrom() != null
        && message.getFrom().length > 0) {
      sender = message.getFrom()[0].toString();
    }
    msg.setSender(sender);

    try {
      msg.setReplyTo(Joiner.on(", ").useForNull("null").join(message.getReplyTo()));
    } catch (NullPointerException e) {
    }

    boolean toAdmins = false;
    Address[] allRecipients = message.getAllRecipients();
    if (allRecipients != null) {
      for (Address addr : allRecipients) {
        if (ADMINS_ADDRESS.equals(addr.toString())) {
          toAdmins = true;
        }
      }
    }

    if (!toAdmins) {
      Set<String> allAddresses = new HashSet<String>();
      for (Address addr : addresses) {
        allAddresses.add(addr.toString());
      }
      msg.setTo(convertAddressFields(message.getRecipients(RecipientType.TO), allAddresses));
      msg.setCc(convertAddressFields(message.getRecipients(RecipientType.CC), allAddresses));
      msg.setBcc(convertAddressFields(message.getRecipients(RecipientType.BCC), allAddresses));
    }

    msg.setSubject(message.getSubject());

    Object textObject = null;
    Object htmlObject = null;
    String textType = null;
    String htmlType = null;
    Multipart otherMessageParts = null;

    List<MailService.Header> headers = new ArrayList<MailService.Header>();
    Enumeration originalHeaders = message.getMatchingHeaders(HEADERS_WHITELIST);
    while (originalHeaders.hasMoreElements()) {
      Header header = (Header) originalHeaders.nextElement();
      headers.add(new MailService.Header(header.getName(), header.getValue()));
    }
    msg.setHeaders(headers);

    if (message.getContentType() == null) {
      try {
        textObject = message.getContent();
        textType = message.getContentType();
      } catch (IOException e) {
        throw new MessagingException("Getting typeless content failed", e);
      }
    } else if (message.isMimeType("text/html")) {
      try {
        htmlObject = message.getContent();
        htmlType = message.getContentType();
      } catch (IOException e) {
        throw new MessagingException("Getting html content failed", e);
      }
    } else if (message.isMimeType("text/*")) {
      try {
        textObject = message.getContent();
        textType = message.getContentType();
      } catch (IOException e) {
        throw new MessagingException("Getting text/* content failed", e);
      }
    } else if (message.isMimeType("multipart/*")) {
      Multipart mp;
      try {
        mp = (Multipart) message.getContent();
        for (int i = 0; i < mp.getCount(); i++) {
          BodyPart bp = mp.getBodyPart(i);
          if (bp.isMimeType("text/plain") && textObject == null) {
            textObject = bp.getContent();
            textType = bp.getContentType();
          } else if (bp.isMimeType("text/html") && htmlObject == null) {
            htmlObject = bp.getContent();
            htmlType = bp.getContentType();
          } else {
            if (otherMessageParts == null) {
              String type = mp.getContentType();
              assert (type.startsWith("multipart/"));
              otherMessageParts = new MimeMultipart(
                  type.substring("multipart/".length()));
            }
            otherMessageParts.addBodyPart(bp);
          }
        }
      } catch (IOException e) {
        throw new MessagingException("Getting multipart content failed", e);
      }
    }

    if (textObject != null) {
      if (textObject instanceof String) {
        msg.setTextBody((String) textObject);
      } else if (textObject instanceof InputStream) {
        try {
          msg.setTextBody(inputStreamToString((InputStream) textObject, textType));
        } catch (IOException e) {
          throw new MessagingException("Stringifying text body failed", e);
        }
      } else {
        throw new MessagingException("Converting text body failed");
      }
    }

    if (htmlObject != null) {
      if (htmlObject instanceof String) {

        msg.setHtmlBody((String) htmlObject);
      } else if (htmlObject instanceof InputStream) {
        try {
          msg.setHtmlBody(inputStreamToString((InputStream) htmlObject, htmlType));
        } catch (IOException e) {
          throw new MessagingException("Stringifying html body failed", e);
        }
      } else {
        throw new MessagingException("Converting html body failed");
      }
    }

    if (otherMessageParts != null) {
      ArrayList<MailService.Attachment> attachments =
          new ArrayList<MailService.Attachment>(otherMessageParts.getCount());
      for (int i = 0; i < otherMessageParts.getCount(); i++) {
        BodyPart bp = otherMessageParts.getBodyPart(i);
        String name = bp.getFileName();
        byte[] data;
        try {
          Object o = bp.getContent();
          if (o instanceof InputStream) {
            data = inputStreamToBytes((InputStream) o);
          } else if (o instanceof String) {
              data = ((String) o).getBytes();
          } else {
            throw new MessagingException("Converting attachment data failed");
          }
        } catch (IOException e) {
          throw new MessagingException("Extracting attachment data failed", e);
        }
        MailService.Attachment attachment =
            new MailService.Attachment(name, data);
        attachments.add(attachment);
      }
      msg.setAttachments(attachments);
    }

    try {
      if (toAdmins) {
        service.sendToAdmins(msg);
      } else {
        service.send(msg);
      }
    } catch (IOException e) {
      notifyTransportListeners(
          TransportEvent.MESSAGE_NOT_DELIVERED, new Address[0], addresses,
          new Address[0], message);
View Full Code Here

Examples of com.google.appengine.api.mail.MailService

      ApiProxy.getCurrentEnvironment().getAttributes().get("com.google.appengine.runtime.default_version_hostname"),
      URLEncoder.encode(confirmationCode, "UTF-8"));
    String body = String.format("You've been invited to administer an instance of " +
            "YouTube Direct. To accept this invitation, please visit %s", url);
   
    MailService mailService = MailServiceFactory.getMailService();
    Message message = new Message();

    message.setSubject("Invitation to Administer YouTube Direct");
    message.setSender(fromAddress);
    message.setTo(toAddress);
    message.setTextBody(body);
    mailService.send(message);
  }
View Full Code Here

Examples of com.google.appengine.api.mail.MailService

  public void sendPhotoEntryToAdmins(PhotoEntry photoEntry) {
    log.info(
        String.format("Sending photo from PhotoEntry id '%s' to admins...", photoEntry.getId()));
    AdminConfig adminConfig = adminConfigDao.getAdminConfig();

    MailService mailService = MailServiceFactory.getMailService();
    Message message = new Message();

    try {
      String fromAddress = adminConfig.getFromAddress();
      if (util.isNullOrEmpty(fromAddress)) {
        throw new IllegalArgumentException("No from address found in configuration.");
      }

      message.setSubject("Unable to submit photo to Picasa");
      message.setSender(fromAddress);
      message.setTextBody("YouTube Direct was unable to upload a photo submission to Picasa.\n\n"
          + "There might be a service issue, or your Picasa configuration might be incorrect.\n\n"
          + "The photo in question is attached.");

      BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
      byte[] photoBytes = blobstoreService.fetchData(
          photoEntry.getBlobKey(), 0, photoEntry.getOriginalFileSize() - 1);

      MailService.Attachment photoAttachment =
          new MailService.Attachment(photoEntry.getOriginalFileName(), photoBytes);
      message.setAttachments(photoAttachment);

      mailService.sendToAdmins(message);
      log.info("Email sent to admins.");
    } catch (IOException e) {
      log.log(Level.WARNING, "", e);
    } catch (IllegalArgumentException e) {
      log.log(Level.WARNING, "", e);
View Full Code Here

Examples of com.google.appengine.api.mail.MailService

        throw new IllegalArgumentException(
            "No notification email addresses found in configuration.");
      }
      String[] addresses = addressCommaSeparated.split("\\s*,\\s*");

      MailService mailService = MailServiceFactory.getMailService();
      Message message = new Message();

      // Default to the first (or only) address in the recipient list to use
      // as From: header.
      message.setSender(addresses[0]);
      message.setTo(addresses);
      message.setSubject(subject);
      message.setTextBody(body);

      mailService.send(message);
    } catch (IOException e) {
      log.log(Level.WARNING, "", e);
    } catch (IllegalArgumentException e) {
      log.info(e.getMessage());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.