Esempio n. 1
0
  /** Enables basic authentication by adding required header. */
  public HttpRequest basicAuthentication(String username, String password) {

    if (username != null && password != null) {
      String data = username.concat(StringPool.COLON).concat(password);

      String base64 = Base64.encodeToString(data);

      header("Authorization", "Basic " + base64, true);
    }

    return this;
  }
Esempio n. 2
0
  private void addAttachments(Multipart multipart, List<Attachment> attachments)
      throws MessagingException {
    for (Attachment attachment : attachments) {
      BasicViewRenderer response = render(attachment.view());
      byte[] base64Encoded = Base64.encodeToByte(response.getOutputAsBytes());

      InternetHeaders headers = new InternetHeaders();
      headers.addHeader(Header.ContentType, response.getContentType());
      headers.addHeader(Header.ContentTransferEncoding, "base64");

      MimeBodyPart part = new MimeBodyPart(headers, base64Encoded);
      part.setFileName(attachment.name());
      part.setDisposition(attachment.disposition().value());

      if (attachment.isInline()) {
        part.setContentID(attachment.contentId());
      }

      multipart.addBodyPart(part);
    }
  }