本文整理了Java中javax.mail.Message.writeTo()
方法的一些代码示例,展示了Message.writeTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.writeTo()
方法的具体详情如下:
包路径:javax.mail.Message
类名称:Message
方法名:writeTo
暂无
代码示例来源:origin: apache/nifi
@Override
public void process(final OutputStream out) throws IOException {
try {
emailMessage.writeTo(out);
} catch (MessagingException e) {
throw new IOException(e);
}
}
});
代码示例来源:origin: oblac/jodd
/**
* Sends a message.
*
* @param msg {@link Message} to send.
* @param addresses array of {@link Address}es to send to.
*/
@Override
public void sendMessage(final Message msg, final Address[] addresses) {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
msg.writeTo(outputStream);
} catch (IOException | MessagingException e) {
throw new MailException(e);
}
eml = outputStream.toString();
}
代码示例来源:origin: oblac/jodd
/**
* Creates EML string from given {@link ReceivedEmail}.
*
* @param receivedEmail {@link ReceivedEmail} from which to create EML {@link String}.
* @return {@link String} with EML content.
*/
public String compose(final ReceivedEmail receivedEmail) {
Message msg = receivedEmail.originalMessage();
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
msg.writeTo(outputStream);
} catch (IOException | MessagingException e) {
throw new MailException(e);
}
return outputStream.toString();
}
代码示例来源:origin: apache/nifi
/**
* Disposes the message by converting it to a {@link FlowFile} transferring
* it to the REL_SUCCESS relationship.
*/
private void transfer(Message emailMessage, ProcessContext context, ProcessSession processSession) {
long start = System.nanoTime();
FlowFile flowFile = processSession.create();
flowFile = processSession.append(flowFile, out -> {
try {
emailMessage.writeTo(out);
} catch (MessagingException e) {
throw new IOException(e);
}
});
long executionDuration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
String fromAddressesString = "";
try {
Address[] fromAddresses = emailMessage.getFrom();
if (fromAddresses != null) {
fromAddressesString = Arrays.asList(fromAddresses).toString();
}
} catch (MessagingException e) {
this.logger.warn("Failed to retrieve 'From' attribute from Message.");
}
processSession.getProvenanceReporter().receive(flowFile, this.displayUrl, "Received message from " + fromAddressesString, executionDuration);
this.getLogger().info("Successfully received {} from {} in {} millis", new Object[]{flowFile, fromAddressesString, executionDuration});
processSession.transfer(flowFile, REL_SUCCESS);
}
代码示例来源:origin: aws/aws-sdk-java
m.writeTo(byteOutput);
SendRawEmailRequest req = new SendRawEmailRequest();
byte[] messageByteArray = ((ByteArrayOutputStream) byteOutput)
代码示例来源:origin: pentaho/pentaho-kettle
/**
* Export message content to a filename.
*
* @param filename
* the target filename
* @param foldername
* the parent folder of filename
* @throws KettleException
*/
public void saveMessageContentToFile( String filename, String foldername ) throws KettleException {
OutputStream os = null;
try {
os = KettleVFS.getOutputStream( foldername + ( foldername.endsWith( "/" ) ? "" : "/" ) + filename, false );
getMessage().writeTo( os );
updateSavedMessagesCounter();
} catch ( Exception e ) {
throw new KettleException( BaseMessages.getString( PKG, "MailConnection.Error.SavingMessageContent", ""
+ this.message.getMessageNumber(), filename, foldername ), e );
} finally {
if ( os != null ) {
IOUtils.closeQuietly( os );
}
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Write the object as a byte stream.
*/
public void writeTo(Object obj, String mimeType, OutputStream os)
throws IOException {
// if the object is a message, we know how to write that out
if (obj instanceof Message) {
Message m = (Message)obj;
try {
m.writeTo(os);
} catch (MessagingException me) {
IOException ioex = new IOException("Exception writing message");
ioex.initCause(me);
throw ioex;
}
} else {
throw new IOException("unsupported object");
}
}
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Write the object as a byte stream.
*/
@Override
public void writeTo(Object obj, String mimeType, OutputStream os)
throws IOException {
// if the object is a message, we know how to write that out
if (obj instanceof Message) {
Message m = (Message)obj;
try {
m.writeTo(os);
} catch (MessagingException me) {
IOException ioex = new IOException("Exception writing message");
ioex.initCause(me);
throw ioex;
}
} else {
throw new IOException("unsupported object");
}
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
public void writeTo(OutputStream os) throws IOException {
// the message should not change between the constructor and this call
try {
if (buf != null)
os.write(buf, 0, msgSize);
else {
os = new CRLFOutputStream(os);
msg.writeTo(os);
}
} catch (MessagingException mex) {
// exceptions here are bad, "should" never happen
throw new IOException("MessagingException while appending message: "
+ mex);
}
}
}
代码示例来源:origin: com.sun.mail/javax.mail
@Override
public void writeTo(OutputStream os) throws IOException {
// the message should not change between the constructor and this call
try {
if (buf != null)
os.write(buf, 0, msgSize);
else {
os = new CRLFOutputStream(os);
msg.writeTo(os);
}
} catch (MessagingException mex) {
// exceptions here are bad, "should" never happen
throw new IOException("MessagingException while appending message: "
+ mex);
}
}
}
代码示例来源:origin: webx/citrus
/** 将javamail邮件对象输出到指定流中。 */
public void writeTo(OutputStream ostream, Session session) throws MailBuilderException, IOException {
Message message = getMessage(session);
try {
message.writeTo(ostream);
} catch (MessagingException e) {
throw new MailBuilderException(e);
}
}
代码示例来源:origin: webx/citrus
/** 将javamail邮件对象输出到指定流中。 */
public void writeTo(OutputStream ostream, Session session) throws MailBuilderException, IOException {
Message message = getMessage(session);
try {
message.writeTo(ostream);
} catch (MessagingException e) {
throw new MailBuilderException(e);
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
final Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER);
try {
msg.writeTo(new ByteArrayOutputStream(MIN_HEADER_SIZE));
} catch (final RuntimeException RE) {
throw RE; //Avoid catch all.
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Converts an email message to a raw string. This raw string
* is passed to the error manager to allow custom error managers
* to recreate the original MimeMessage object.
* @param msg a Message object.
* @return the raw string or null if msg was null.
* @throws MessagingException if there was a problem with the message.
* @throws IOException if there was a problem.
*/
private String toRawString(final Message msg) throws MessagingException, IOException {
if (msg != null) {
Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER);
try { //BUGID 8025251
int nbytes = Math.max(msg.getSize() + MIN_HEADER_SIZE, MIN_HEADER_SIZE);
ByteArrayOutputStream out = new ByteArrayOutputStream(nbytes);
msg.writeTo(out);
return out.toString("US-ASCII"); //Raw message is always ASCII.
} finally {
getAndSetContextClassLoader(ccl);
}
} else { //Must match this.reportError behavior, see push method.
return null; //Null is the safe choice.
}
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Converts an email message to a raw string. This raw string
* is passed to the error manager to allow custom error managers
* to recreate the original MimeMessage object.
* @param msg a Message object.
* @return the raw string or null if msg was null.
* @throws MessagingException if there was a problem with the message.
* @throws IOException if there was a problem.
*/
private String toRawString(final Message msg) throws MessagingException, IOException {
if (msg != null) {
Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER);
try { //JDK-8025251
int nbytes = Math.max(msg.getSize() + MIN_HEADER_SIZE, MIN_HEADER_SIZE);
ByteArrayOutputStream out = new ByteArrayOutputStream(nbytes);
msg.writeTo(out); //Headers can be UTF-8 or US-ASCII.
return out.toString("UTF-8");
} finally {
getAndSetContextClassLoader(ccl);
}
} else { //Must match this.reportError behavior, see push method.
return null; //Null is the safe choice.
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
public MessageLiteral(Message msg, int maxsize)
throws MessagingException, IOException {
this.msg = msg;
// compute the size here so exceptions can be returned immediately
LengthCounter lc = new LengthCounter(maxsize);
OutputStream os = new CRLFOutputStream(lc);
msg.writeTo(os);
os.flush();
msgSize = lc.getSize();
buf = lc.getBytes();
}
代码示例来源:origin: com.sun.mail/javax.mail
public MessageLiteral(Message msg, int maxsize)
throws MessagingException, IOException {
this.msg = msg;
// compute the size here so exceptions can be returned immediately
LengthCounter lc = new LengthCounter(maxsize);
OutputStream os = new CRLFOutputStream(lc);
msg.writeTo(os);
os.flush();
msgSize = lc.getSize();
buf = lc.getBytes();
}
代码示例来源:origin: com.sun.mail/javax.mail
final Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER);
try {
msg.writeTo(new ByteArrayOutputStream(MIN_HEADER_SIZE));
} catch (final RuntimeException RE) {
throw RE; //Avoid catch all.
代码示例来源:origin: webx/citrus
/** 将javamail邮件对象转换成文本形式,其格式为标准的<code>.eml</code>格式。 */
public static String toString(Message message, String javaCharset) throws MessagingException,
UnsupportedEncodingException {
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
try {
message.writeTo(ostream);
} catch (IOException e) {
unexpectedException(e);
} finally {
ostream.close();
}
ByteArray bytes = ostream.toByteArray();
javaCharset = getJavaCharset(javaCharset);
return new String(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength(), javaCharset);
}
代码示例来源:origin: webx/citrus
/** 将javamail邮件对象转换成文本形式,其格式为标准的<code>.eml</code>格式。 */
public static String toString(Message message, String javaCharset) throws MessagingException,
UnsupportedEncodingException {
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
try {
message.writeTo(ostream);
} catch (IOException e) {
unexpectedException(e);
} finally {
ostream.close();
}
ByteArray bytes = ostream.toByteArray();
javaCharset = getJavaCharset(javaCharset);
return new String(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength(), javaCharset);
}
内容来源于网络,如有侵权,请联系作者删除!