本文整理汇总了Java中javax.mail.BodyPart.setDisposition方法的典型用法代码示例。如果您正苦于以下问题:Java BodyPart.setDisposition方法的具体用法?Java BodyPart.setDisposition怎么用?Java BodyPart.setDisposition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.BodyPart
的用法示例。
在下文中一共展示了BodyPart.setDisposition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBodyPart
import javax.mail.BodyPart; //导入方法依赖的package包/类
public BodyPart getBodyPart() {
try {
DataSource dataSource = new DataSource() {
@Override public String getContentType() { return contentType; }
@Override public InputStream getInputStream() { return new ByteArrayInputStream(body.toByteArray()); }
@Override public String getName() { return filenameOrNull; }
@Override public OutputStream getOutputStream() { throw new RuntimeException("unreachable"); }
};
BodyPart filePart = new MimeBodyPart();
filePart.setDataHandler(new DataHandler(dataSource));
if (filenameOrNull != null) {
filePart.setFileName(filenameOrNull);
filePart.setDisposition(Part.ATTACHMENT);
}
return filePart;
}
catch (MessagingException e) { throw new RuntimeException(e); }
}
示例2: getBodyPartFromDatasource
import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
* Helper method which generates a {@link BodyPart} from an {@link AttachmentResource} (from its {@link DataSource}) and a disposition type
* ({@link Part#INLINE} or {@link Part#ATTACHMENT}). With this the attachment data can be converted into objects that fit in the email structure.
* <p>
* For every attachment and embedded image a header needs to be set.
*
* @param attachmentResource An object that describes the attachment and contains the actual content data.
* @param dispositionType The type of attachment, {@link Part#INLINE} or {@link Part#ATTACHMENT} .
*
* @return An object with the attachment data read for placement in the email structure.
* @throws MessagingException All BodyPart setters.
*/
private static BodyPart getBodyPartFromDatasource(final AttachmentResource attachmentResource, final String dispositionType)
throws MessagingException {
final BodyPart attachmentPart = new MimeBodyPart();
// setting headers isn't working nicely using the javax mail API, so let's do that manually
final String resourceName = determineResourceName(attachmentResource, false);
final String fileName = determineResourceName(attachmentResource, true);
attachmentPart.setDataHandler(new DataHandler(new NamedDataSource(fileName, attachmentResource.getDataSource())));
attachmentPart.setFileName(fileName);
final String contentType = attachmentResource.getDataSource().getContentType();
attachmentPart.setHeader("Content-Type", contentType + "; filename=" + fileName + "; name=" + resourceName);
attachmentPart.setHeader("Content-ID", format("<%s>", resourceName));
attachmentPart.setDisposition(dispositionType);
return attachmentPart;
}
示例3: setBodyPart
import javax.mail.BodyPart; //导入方法依赖的package包/类
public static void setBodyPart(Multipart multipart, byte[] content, String contentType) throws MessagingException {
String disposition = null;
for (int i = 0; i < multipart.getCount(); i++) {
BodyPart bp = multipart.getBodyPart(i);
if (contentType.equalsIgnoreCase(bp.getContentType())) {
disposition = bp.getDisposition();
multipart.removeBodyPart(i);
break;
}
}
InternetHeaders ih1 = new InternetHeaders();
ih1.setHeader("Content-Type", contentType);
BodyPart bodyPart = new MimeBodyPart(ih1, content);
if (disposition != null) {
bodyPart.setDisposition(disposition);
}
multipart.addBodyPart(bodyPart);
}
示例4: addAttachmentsToMultipart
import javax.mail.BodyPart; //导入方法依赖的package包/类
protected void addAttachmentsToMultipart(MimeMultipart multipart, String partDisposition,
AttachmentsContentTransferEncodingResolver encodingResolver, Exchange exchange) throws MessagingException {
LOG.trace("Adding attachments +++ start +++");
int i = 0;
for (Map.Entry<String, DataHandler> entry : exchange.getIn().getAttachments().entrySet()) {
String attachmentFilename = entry.getKey();
DataHandler handler = entry.getValue();
if (LOG.isTraceEnabled()) {
LOG.trace("Attachment #{}: Disposition: {}", i, partDisposition);
LOG.trace("Attachment #{}: DataHandler: {}", i, handler);
LOG.trace("Attachment #{}: FileName: {}", i, attachmentFilename);
}
if (handler != null) {
if (shouldAddAttachment(exchange, attachmentFilename, handler)) {
// Create another body part
BodyPart messageBodyPart = new MimeBodyPart();
// Set the data handler to the attachment
messageBodyPart.setDataHandler(handler);
if (attachmentFilename.toLowerCase().startsWith("cid:")) {
// add a Content-ID header to the attachment
// must use angle brackets according to RFC: http://www.ietf.org/rfc/rfc2392.txt
messageBodyPart.addHeader("Content-ID", "<" + attachmentFilename.substring(4) + ">");
// Set the filename without the cid
messageBodyPart.setFileName(attachmentFilename.substring(4));
} else {
// Set the filename
messageBodyPart.setFileName(attachmentFilename);
}
LOG.trace("Attachment #" + i + ": ContentType: " + messageBodyPart.getContentType());
if (contentTypeResolver != null) {
String contentType = contentTypeResolver.resolveContentType(attachmentFilename);
LOG.trace("Attachment #" + i + ": Using content type resolver: " + contentTypeResolver + " resolved content type as: " + contentType);
if (contentType != null) {
String value = contentType + "; name=" + attachmentFilename;
messageBodyPart.setHeader("Content-Type", value);
LOG.trace("Attachment #" + i + ": ContentType: " + messageBodyPart.getContentType());
}
}
// set Content-Transfer-Encoding using resolver if possible
resolveContentTransferEncoding(encodingResolver, i, messageBodyPart);
// Set Disposition
messageBodyPart.setDisposition(partDisposition);
// Add part to multipart
multipart.addBodyPart(messageBodyPart);
} else {
LOG.trace("shouldAddAttachment: false");
}
} else {
LOG.warn("Cannot add attachment: " + attachmentFilename + " as DataHandler is null");
}
i++;
}
LOG.trace("Adding attachments +++ done +++");
}
示例5: sendMultipartMessageText
import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
* Send a Multipart text message with attached files. FIXME: use prepareMessage method
*
* @param strRecipientsTo
* The list of the main recipients email.Every recipient must be separated by the mail separator defined in config.properties
* @param strRecipientsCc
* The recipients list of the carbon copies .
* @param strRecipientsBcc
* The recipients list of the blind carbon copies .
* @param strSenderName
* The sender name.
* @param strSenderEmail
* The sender email address.
* @param strSubject
* The message subject.
* @param strMessage
* The message.
* @param fileAttachements
* The list of attached files
* @param transport
* the smtp transport object
* @param session
* the smtp session object
* @throws AddressException
* If invalid address
* @throws SendFailedException
* If an error occured during sending
* @throws MessagingException
* If a messaging error occured
*/
protected static void sendMultipartMessageText( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName,
String strSenderEmail, String strSubject, String strMessage, List<FileAttachment> fileAttachements, Transport transport, Session session )
throws MessagingException, AddressException, SendFailedException
{
Message msg = prepareMessage( strRecipientsTo, strRecipientsCc, strRecipientsBcc, strSenderName, strSenderEmail, strSubject, session );
msg.setHeader( HEADER_NAME, HEADER_VALUE );
// Creation of the root part containing all the elements of the message
MimeMultipart multipart = new MimeMultipart( );
// Creation of the html part, the "core" of the message
BodyPart msgBodyPart = new MimeBodyPart( );
// msgBodyPart.setContent( strMessage, BODY_PART_MIME_TYPE );
msgBodyPart.setDataHandler( new DataHandler( new ByteArrayDataSource( strMessage, AppPropertiesService.getProperty( PROPERTY_MAIL_TYPE_PLAIN )
+ AppPropertiesService.getProperty( PROPERTY_CHARSET ) ) ) );
multipart.addBodyPart( msgBodyPart );
// add File Attachement
if ( fileAttachements != null )
{
for ( FileAttachment fileAttachement : fileAttachements )
{
String strFileName = fileAttachement.getFileName( );
byte [ ] bContentFile = fileAttachement.getData( );
String strContentType = fileAttachement.getType( );
ByteArrayDataSource dataSource = new ByteArrayDataSource( bContentFile, strContentType );
msgBodyPart = new MimeBodyPart( );
msgBodyPart.setDataHandler( new DataHandler( dataSource ) );
msgBodyPart.setFileName( strFileName );
msgBodyPart.setDisposition( CONSTANT_DISPOSITION_ATTACHMENT );
multipart.addBodyPart( msgBodyPart );
}
}
msg.setContent( multipart );
sendMessage( msg, transport );
}
示例6: main
import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
MimeMultipart mmp = new MimeMultipart();
BodyPart bp = new MimeBodyPart(new FileInputStream("C:\\Git\\mod-files\\ramls\\mod-files\\files.raml"));
bp.setDisposition("form-data");
bp.setFileName("abc.raml");
BodyPart bp2 = new MimeBodyPart(new FileInputStream("C:\\Git\\mod-files\\ramls\\mod-files\\files.raml"));
bp2.setDisposition("form-data");
bp2.setFileName("abcd.raml");
mmp.addBodyPart(bp);
mmp.addBodyPart(bp2);
AdminClient aClient = new AdminClient("localhost", 8888, null, null, false);
aClient.postUploadmultipart(PersistMethod.SAVE, null, "abc",
mmp, reply -> {
reply.statusCode();
});
/* aClient.postImportSQL(
Test.class.getClassLoader().getResourceAsStream("create_config.sql"), reply -> {
reply.statusCode();
});*/
aClient.getJstack( trace -> {
trace.bodyHandler( content -> {
System.out.println(content);
});
});
TenantClient tc = new TenantClient("localhost", 8888, "harvard", "harvard");
tc.post(null, response -> {
response.bodyHandler( body -> {
System.out.println(body.toString());
tc.delete( reply -> {
reply.bodyHandler( body2 -> {
System.out.println(body2.toString());
});
});
});
});
aClient.getPostgresActiveSessions("postgres", reply -> {
reply.bodyHandler( body -> {
System.out.println(body.toString("UTF8"));
});
});
aClient.getPostgresLoad("postgres", reply -> {
reply.bodyHandler( body -> {
System.out.println(body.toString("UTF8"));
});
});
aClient.getPostgresTableAccessStats( reply -> {
reply.bodyHandler( body -> {
System.out.println(body.toString("UTF8"));
});
});
aClient.getPostgresTableSize("postgres", reply -> {
reply.bodyHandler( body -> {
System.out.println(body.toString("UTF8"));
});
});
}