javax.mail.Message.writeTo()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(309)

本文整理了Java中javax.mail.Message.writeTo()方法的一些代码示例,展示了Message.writeTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.writeTo()方法的具体详情如下:
包路径:javax.mail.Message
类名称:Message
方法名:writeTo

Message.writeTo介绍

暂无

代码示例

代码示例来源:origin: apache/nifi

  1. @Override
  2. public void process(final OutputStream out) throws IOException {
  3. try {
  4. emailMessage.writeTo(out);
  5. } catch (MessagingException e) {
  6. throw new IOException(e);
  7. }
  8. }
  9. });

代码示例来源:origin: oblac/jodd

  1. /**
  2. * Sends a message.
  3. *
  4. * @param msg {@link Message} to send.
  5. * @param addresses array of {@link Address}es to send to.
  6. */
  7. @Override
  8. public void sendMessage(final Message msg, final Address[] addresses) {
  9. final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  10. try {
  11. msg.writeTo(outputStream);
  12. } catch (IOException | MessagingException e) {
  13. throw new MailException(e);
  14. }
  15. eml = outputStream.toString();
  16. }

代码示例来源:origin: oblac/jodd

  1. /**
  2. * Creates EML string from given {@link ReceivedEmail}.
  3. *
  4. * @param receivedEmail {@link ReceivedEmail} from which to create EML {@link String}.
  5. * @return {@link String} with EML content.
  6. */
  7. public String compose(final ReceivedEmail receivedEmail) {
  8. Message msg = receivedEmail.originalMessage();
  9. final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  10. try {
  11. msg.writeTo(outputStream);
  12. } catch (IOException | MessagingException e) {
  13. throw new MailException(e);
  14. }
  15. return outputStream.toString();
  16. }

代码示例来源:origin: apache/nifi

  1. /**
  2. * Disposes the message by converting it to a {@link FlowFile} transferring
  3. * it to the REL_SUCCESS relationship.
  4. */
  5. private void transfer(Message emailMessage, ProcessContext context, ProcessSession processSession) {
  6. long start = System.nanoTime();
  7. FlowFile flowFile = processSession.create();
  8. flowFile = processSession.append(flowFile, out -> {
  9. try {
  10. emailMessage.writeTo(out);
  11. } catch (MessagingException e) {
  12. throw new IOException(e);
  13. }
  14. });
  15. long executionDuration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
  16. String fromAddressesString = "";
  17. try {
  18. Address[] fromAddresses = emailMessage.getFrom();
  19. if (fromAddresses != null) {
  20. fromAddressesString = Arrays.asList(fromAddresses).toString();
  21. }
  22. } catch (MessagingException e) {
  23. this.logger.warn("Failed to retrieve 'From' attribute from Message.");
  24. }
  25. processSession.getProvenanceReporter().receive(flowFile, this.displayUrl, "Received message from " + fromAddressesString, executionDuration);
  26. this.getLogger().info("Successfully received {} from {} in {} millis", new Object[]{flowFile, fromAddressesString, executionDuration});
  27. processSession.transfer(flowFile, REL_SUCCESS);
  28. }

代码示例来源:origin: aws/aws-sdk-java

  1. m.writeTo(byteOutput);
  2. SendRawEmailRequest req = new SendRawEmailRequest();
  3. byte[] messageByteArray = ((ByteArrayOutputStream) byteOutput)

代码示例来源:origin: pentaho/pentaho-kettle

  1. /**
  2. * Export message content to a filename.
  3. *
  4. * @param filename
  5. * the target filename
  6. * @param foldername
  7. * the parent folder of filename
  8. * @throws KettleException
  9. */
  10. public void saveMessageContentToFile( String filename, String foldername ) throws KettleException {
  11. OutputStream os = null;
  12. try {
  13. os = KettleVFS.getOutputStream( foldername + ( foldername.endsWith( "/" ) ? "" : "/" ) + filename, false );
  14. getMessage().writeTo( os );
  15. updateSavedMessagesCounter();
  16. } catch ( Exception e ) {
  17. throw new KettleException( BaseMessages.getString( PKG, "MailConnection.Error.SavingMessageContent", ""
  18. + this.message.getMessageNumber(), filename, foldername ), e );
  19. } finally {
  20. if ( os != null ) {
  21. IOUtils.closeQuietly( os );
  22. }
  23. }
  24. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * Write the object as a byte stream.
  3. */
  4. public void writeTo(Object obj, String mimeType, OutputStream os)
  5. throws IOException {
  6. // if the object is a message, we know how to write that out
  7. if (obj instanceof Message) {
  8. Message m = (Message)obj;
  9. try {
  10. m.writeTo(os);
  11. } catch (MessagingException me) {
  12. IOException ioex = new IOException("Exception writing message");
  13. ioex.initCause(me);
  14. throw ioex;
  15. }
  16. } else {
  17. throw new IOException("unsupported object");
  18. }
  19. }
  20. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. /**
  2. * Write the object as a byte stream.
  3. */
  4. @Override
  5. public void writeTo(Object obj, String mimeType, OutputStream os)
  6. throws IOException {
  7. // if the object is a message, we know how to write that out
  8. if (obj instanceof Message) {
  9. Message m = (Message)obj;
  10. try {
  11. m.writeTo(os);
  12. } catch (MessagingException me) {
  13. IOException ioex = new IOException("Exception writing message");
  14. ioex.initCause(me);
  15. throw ioex;
  16. }
  17. } else {
  18. throw new IOException("unsupported object");
  19. }
  20. }
  21. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. public void writeTo(OutputStream os) throws IOException {
  2. // the message should not change between the constructor and this call
  3. try {
  4. if (buf != null)
  5. os.write(buf, 0, msgSize);
  6. else {
  7. os = new CRLFOutputStream(os);
  8. msg.writeTo(os);
  9. }
  10. } catch (MessagingException mex) {
  11. // exceptions here are bad, "should" never happen
  12. throw new IOException("MessagingException while appending message: "
  13. + mex);
  14. }
  15. }
  16. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. @Override
  2. public void writeTo(OutputStream os) throws IOException {
  3. // the message should not change between the constructor and this call
  4. try {
  5. if (buf != null)
  6. os.write(buf, 0, msgSize);
  7. else {
  8. os = new CRLFOutputStream(os);
  9. msg.writeTo(os);
  10. }
  11. } catch (MessagingException mex) {
  12. // exceptions here are bad, "should" never happen
  13. throw new IOException("MessagingException while appending message: "
  14. + mex);
  15. }
  16. }
  17. }

代码示例来源:origin: webx/citrus

  1. /** 将javamail邮件对象输出到指定流中。 */
  2. public void writeTo(OutputStream ostream, Session session) throws MailBuilderException, IOException {
  3. Message message = getMessage(session);
  4. try {
  5. message.writeTo(ostream);
  6. } catch (MessagingException e) {
  7. throw new MailBuilderException(e);
  8. }
  9. }

代码示例来源:origin: webx/citrus

  1. /** 将javamail邮件对象输出到指定流中。 */
  2. public void writeTo(OutputStream ostream, Session session) throws MailBuilderException, IOException {
  3. Message message = getMessage(session);
  4. try {
  5. message.writeTo(ostream);
  6. } catch (MessagingException e) {
  7. throw new MailBuilderException(e);
  8. }
  9. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. final Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER);
  2. try {
  3. msg.writeTo(new ByteArrayOutputStream(MIN_HEADER_SIZE));
  4. } catch (final RuntimeException RE) {
  5. throw RE; //Avoid catch all.

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * Converts an email message to a raw string. This raw string
  3. * is passed to the error manager to allow custom error managers
  4. * to recreate the original MimeMessage object.
  5. * @param msg a Message object.
  6. * @return the raw string or null if msg was null.
  7. * @throws MessagingException if there was a problem with the message.
  8. * @throws IOException if there was a problem.
  9. */
  10. private String toRawString(final Message msg) throws MessagingException, IOException {
  11. if (msg != null) {
  12. Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER);
  13. try { //BUGID 8025251
  14. int nbytes = Math.max(msg.getSize() + MIN_HEADER_SIZE, MIN_HEADER_SIZE);
  15. ByteArrayOutputStream out = new ByteArrayOutputStream(nbytes);
  16. msg.writeTo(out);
  17. return out.toString("US-ASCII"); //Raw message is always ASCII.
  18. } finally {
  19. getAndSetContextClassLoader(ccl);
  20. }
  21. } else { //Must match this.reportError behavior, see push method.
  22. return null; //Null is the safe choice.
  23. }
  24. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. /**
  2. * Converts an email message to a raw string. This raw string
  3. * is passed to the error manager to allow custom error managers
  4. * to recreate the original MimeMessage object.
  5. * @param msg a Message object.
  6. * @return the raw string or null if msg was null.
  7. * @throws MessagingException if there was a problem with the message.
  8. * @throws IOException if there was a problem.
  9. */
  10. private String toRawString(final Message msg) throws MessagingException, IOException {
  11. if (msg != null) {
  12. Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER);
  13. try { //JDK-8025251
  14. int nbytes = Math.max(msg.getSize() + MIN_HEADER_SIZE, MIN_HEADER_SIZE);
  15. ByteArrayOutputStream out = new ByteArrayOutputStream(nbytes);
  16. msg.writeTo(out); //Headers can be UTF-8 or US-ASCII.
  17. return out.toString("UTF-8");
  18. } finally {
  19. getAndSetContextClassLoader(ccl);
  20. }
  21. } else { //Must match this.reportError behavior, see push method.
  22. return null; //Null is the safe choice.
  23. }
  24. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. public MessageLiteral(Message msg, int maxsize)
  2. throws MessagingException, IOException {
  3. this.msg = msg;
  4. // compute the size here so exceptions can be returned immediately
  5. LengthCounter lc = new LengthCounter(maxsize);
  6. OutputStream os = new CRLFOutputStream(lc);
  7. msg.writeTo(os);
  8. os.flush();
  9. msgSize = lc.getSize();
  10. buf = lc.getBytes();
  11. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. public MessageLiteral(Message msg, int maxsize)
  2. throws MessagingException, IOException {
  3. this.msg = msg;
  4. // compute the size here so exceptions can be returned immediately
  5. LengthCounter lc = new LengthCounter(maxsize);
  6. OutputStream os = new CRLFOutputStream(lc);
  7. msg.writeTo(os);
  8. os.flush();
  9. msgSize = lc.getSize();
  10. buf = lc.getBytes();
  11. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. final Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER);
  2. try {
  3. msg.writeTo(new ByteArrayOutputStream(MIN_HEADER_SIZE));
  4. } catch (final RuntimeException RE) {
  5. throw RE; //Avoid catch all.

代码示例来源:origin: webx/citrus

  1. /** 将javamail邮件对象转换成文本形式,其格式为标准的<code>.eml</code>格式。 */
  2. public static String toString(Message message, String javaCharset) throws MessagingException,
  3. UnsupportedEncodingException {
  4. ByteArrayOutputStream ostream = new ByteArrayOutputStream();
  5. try {
  6. message.writeTo(ostream);
  7. } catch (IOException e) {
  8. unexpectedException(e);
  9. } finally {
  10. ostream.close();
  11. }
  12. ByteArray bytes = ostream.toByteArray();
  13. javaCharset = getJavaCharset(javaCharset);
  14. return new String(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength(), javaCharset);
  15. }

代码示例来源:origin: webx/citrus

  1. /** 将javamail邮件对象转换成文本形式,其格式为标准的<code>.eml</code>格式。 */
  2. public static String toString(Message message, String javaCharset) throws MessagingException,
  3. UnsupportedEncodingException {
  4. ByteArrayOutputStream ostream = new ByteArrayOutputStream();
  5. try {
  6. message.writeTo(ostream);
  7. } catch (IOException e) {
  8. unexpectedException(e);
  9. } finally {
  10. ostream.close();
  11. }
  12. ByteArray bytes = ostream.toByteArray();
  13. javaCharset = getJavaCharset(javaCharset);
  14. return new String(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength(), javaCharset);
  15. }

相关文章