本文整理了Java中javax.mail.internet.MimeBodyPart.setText()
方法的一些代码示例,展示了MimeBodyPart.setText()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeBodyPart.setText()
方法的具体详情如下:
包路径:javax.mail.internet.MimeBodyPart
类名称:MimeBodyPart
方法名:setText
[英]Convenience method that sets the given String as this part's content, with a MIME type of "text/plain". If the string contains non US-ASCII characters, it will be encoded using the platform's default charset. The charset is also used to set the "charset" parameter.
Note that there may be a performance penalty if text
is large, since this method may have to scan all the characters to determine what charset to use.
If the charset is already known, use the setText
method that takes the charset parameter.
[中]将给定字符串设置为该部分内容的便捷方法,MIME类型为“text/plain”。如果字符串包含非US-ASCII字符,则将使用平台的默认字符集对其进行编码。字符集还用于设置“charset”参数。
请注意,如果text
较大,可能会导致性能下降,因为此方法可能必须扫描所有字符以确定要使用的字符集。
如果字符集已知,请使用接受字符集参数的setText
方法。
代码示例来源:origin: stackoverflow.com
MimeBodyPart textPart = new MimeBodyPart();
textPart.setText(text, "utf-8");
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(html, "text/html; charset=utf-8");
multiPart.addBodyPart(textPart); // <-- first
multiPart.addBodyPart(htmlPart); // <-- second
message.setContent(multiPart);
代码示例来源:origin: stackoverflow.com
textPart.setText( text, "utf-8" );
代码示例来源:origin: pentaho/pentaho-kettle
private Object createMessageContent() throws IOException, MessagingException {
MimeMultipart content = new MimeMultipart();
MimeBodyPart contentText = new MimeBodyPart();
contentText.setText( "Hello World!" );
content.addBodyPart( contentText );
MimeBodyPart contentFile = new MimeBodyPart();
File testFile = TestUtils.getInputFile( "GetPOP", "txt" );
FileDataSource fds = new FileDataSource( testFile.getAbsolutePath() );
contentFile.setDataHandler( new DataHandler( fds ) );
contentFile.setFileName( testFile.getName() );
content.addBodyPart( contentFile );
return content;
}
代码示例来源:origin: javamelody/javamelody
mbp.setText(message);
final Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mbp);
代码示例来源:origin: igniterealtime/Openfire
text.setText(textBody, encoding);
text.setDisposition(Part.INLINE);
content.addBodyPart(text);
bPart.setText(textBody, encoding);
bPart.setDisposition(Part.INLINE);
bPart.setHeader("Content-Transfer-Encoding", "8bit");
代码示例来源:origin: pentaho/pentaho-kettle
part1.setText( messageText.toString() );
代码示例来源:origin: pentaho/pentaho-kettle
part1.setText( messageText.toString() );
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Convenience method that sets the given String as this part's
* content, with a MIME type of "text/plain" and the specified
* charset. The given Unicode string will be charset-encoded
* using the specified charset. The charset is also used to set
* the "charset" parameter.
*
* @param text the text content to set
* @param charset the charset to use for the text
* @exception MessagingException if an error occurs
*/
public void setText(String text, String charset)
throws MessagingException {
MimeBodyPart.setText(this, text, charset, "plain");
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Convenience method that sets the given String as this part's
* content, with a MIME type of "text/plain" and the specified
* charset. The given Unicode string will be charset-encoded
* using the specified charset. The charset is also used to set
* the "charset" parameter.
*
* @param text the text content to set
* @param charset the charset to use for the text
* @exception MessagingException if an error occurs
*/
public void setText(String text, String charset)
throws MessagingException {
setText(this, text, charset, "plain");
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Convenience method that sets the given String as this part's
* content, with a MIME type of "text/plain" and the specified
* charset. The given Unicode string will be charset-encoded
* using the specified charset. The charset is also used to set
* the "charset" parameter.
*
* @param text the text content to set
* @param charset the charset to use for the text
* @exception MessagingException if an error occurs
*/
@Override
public void setText(String text, String charset)
throws MessagingException {
setText(this, text, charset, "plain");
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Convenience method that sets the given String as this part's
* content, with a primary MIME type of "text" and the specified
* MIME subtype. The given Unicode string will be charset-encoded
* using the specified charset. The charset is also used to set
* the "charset" parameter.
*
* @param text the text content to set
* @param charset the charset to use for the text
* @param subtype the MIME subtype to use (e.g., "html")
* @exception MessagingException if an error occurs
* @since JavaMail 1.4
*/
public void setText(String text, String charset, String subtype)
throws MessagingException {
setText(this, text, charset, subtype);
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Convenience method that sets the given String as this part's
* content, with a primary MIME type of "text" and the specified
* MIME subtype. The given Unicode string will be charset-encoded
* using the specified charset. The charset is also used to set
* the "charset" parameter.
*
* @param text the text content to set
* @param charset the charset to use for the text
* @param subtype the MIME subtype to use (e.g., "html")
* @exception MessagingException if an error occurs
* @since JavaMail 1.4
*/
@Override
public void setText(String text, String charset, String subtype)
throws MessagingException {
MimeBodyPart.setText(this, text, charset, subtype);
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Convenience method that sets the given String as this part's
* content, with a primary MIME type of "text" and the specified
* MIME subtype. The given Unicode string will be charset-encoded
* using the specified charset. The charset is also used to set
* the "charset" parameter.
*
* @param text the text content to set
* @param charset the charset to use for the text
* @param subtype the MIME subtype to use (e.g., "html")
* @exception MessagingException if an error occurs
* @since JavaMail 1.4
*/
@Override
public void setText(String text, String charset, String subtype)
throws MessagingException {
setText(this, text, charset, subtype);
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Convenience method that sets the given String as this part's
* content, with a MIME type of "text/plain" and the specified
* charset. The given Unicode string will be charset-encoded
* using the specified charset. The charset is also used to set
* the "charset" parameter.
*
* @param text the text content to set
* @param charset the charset to use for the text
* @exception MessagingException if an error occurs
*/
@Override
public void setText(String text, String charset)
throws MessagingException {
MimeBodyPart.setText(this, text, charset, "plain");
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Convenience method that sets the given String as this part's
* content, with a primary MIME type of "text" and the specified
* MIME subtype. The given Unicode string will be charset-encoded
* using the specified charset. The charset is also used to set
* the "charset" parameter.
*
* @param text the text content to set
* @param charset the charset to use for the text
* @param subtype the MIME subtype to use (e.g., "html")
* @exception MessagingException if an error occurs
* @since JavaMail 1.4
*/
public void setText(String text, String charset, String subtype)
throws MessagingException {
MimeBodyPart.setText(this, text, charset, subtype);
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Convenience method that sets the given String as this
* part's content, with a MIME type of "text/plain". If the
* string contains non US-ASCII characters, it will be encoded
* using the platform's default charset. The charset is also
* used to set the "charset" parameter. <p>
*
* Note that there may be a performance penalty if
* <code>text</code> is large, since this method may have
* to scan all the characters to determine what charset to
* use. <p>
*
* If the charset is already known, use the
* <code>setText</code> method that takes the charset parameter.
*
* @param text the text content to set
* @exception MessagingException if an error occurs
* @see #setText(String text, String charset)
*/
@Override
public void setText(String text) throws MessagingException {
setText(text, null);
}
代码示例来源:origin: stackoverflow.com
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setText(""
+ "<html>"
+ " <body>"
+ " <p>Here is my image:</p>"
+ " <img src=\"cid:" + cid + "\" />",
+ " </body>"
+ "</html>"
"US-ASCII", "html");
content.addBodyPart(htmlPart);
代码示例来源:origin: stackoverflow.com
// Unformatted text version
final MimeBodyPart textPart = new MimeBodyPart();
textPart.setText("plain content");
// HTML version
final MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent("<b>html content</b>", "text/html");
// Create the Multipart. Add BodyParts to it.
final Multipart mp = new MimeMultipart();
mp.addBodyPart(textPart);
mp.addBodyPart(htmlPart);
// Set Multipart as the message's content
msg.setContent(mp);
代码示例来源:origin: psi-probe/psi-probe
/**
* Creates the message body part.
*
* @param body the body
* @param html the html
* @return the mime body part
* @throws MessagingException the messaging exception
*/
private static MimeBodyPart createMessageBodyPart(String body, boolean html)
throws MessagingException {
MimeBodyPart bodyPart = new MimeBodyPart();
bodyPart.setText(body);
bodyPart.setHeader("content-type", html ? "text/html" : "text/plain");
return bodyPart;
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Set the content for a part using the encoding assigned to the handler.
* @param part the part to assign.
* @param buf the formatted data.
* @param type the mime type.
* @throws MessagingException if there is a problem.
*/
private void setContent(MimeBodyPart part, CharSequence buf, String type) throws MessagingException {
final String charset = getEncodingName();
if (type != null && !"text/plain".equalsIgnoreCase(type)) {
type = contentWithEncoding(type, charset);
try {
DataSource source = new ByteArrayDataSource(buf.toString(), type);
part.setDataHandler(new DataHandler(source));
} catch (final IOException IOE) {
reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE);
part.setText(buf.toString(), charset);
}
} else {
part.setText(buf.toString(), MimeUtility.mimeCharset(charset));
}
}
内容来源于网络,如有侵权,请联系作者删除!