javax.mail.internet.MimeMultipart.<init>()方法的使用及代码示例

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

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

MimeMultipart.<init>介绍

[英]Default constructor. An empty MimeMultipart object is created. Its content type is set to "multipart/mixed". A unique boundary string is generated and this string is setup as the "boundary" parameter for the contentType field.

MimeBodyParts may be added later.
[中]默认构造函数。将创建一个空的mimultipart对象。其内容类型设置为“多部分/混合”。将生成唯一的边界字符串,并将此字符串设置为contentType字段的“边界”参数。
MimeBodyParts可能会在以后添加。

代码示例

代码示例来源:origin: spring-projects/spring-framework

break;
case MULTIPART_MODE_MIXED:
  MimeMultipart mixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
  mimeMessage.setContent(mixedMultipart);
  setMimeMultiparts(mixedMultipart, mixedMultipart);
  break;
case MULTIPART_MODE_RELATED:
  MimeMultipart relatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
  mimeMessage.setContent(relatedMultipart);
  setMimeMultiparts(relatedMultipart, relatedMultipart);
  break;
case MULTIPART_MODE_MIXED_RELATED:
  MimeMultipart rootMixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
  mimeMessage.setContent(rootMixedMultipart);
  MimeMultipart nestedRelatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
  MimeBodyPart relatedBodyPart = new MimeBodyPart();
  relatedBodyPart.setContent(nestedRelatedMultipart);
  rootMixedMultipart.addBodyPart(relatedBodyPart);

代码示例来源:origin: blynkkk/blynk-server

@Override
public void sendHtmlWithAttachment(String to, String subj, String body,
                  QrHolder[] attachmentData) throws Exception {
  MimeMessage message = new MimeMessage(session);
  message.setFrom(from);
  message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
  message.setSubject(subj, "UTF-8");
  Multipart multipart = new MimeMultipart();
  MimeBodyPart bodyMessagePart = new MimeBodyPart();
  bodyMessagePart.setContent(body, TEXT_HTML_CHARSET_UTF_8);
  multipart.addBodyPart(bodyMessagePart);
  attachQRs(multipart, attachmentData);
  attachCSV(multipart, attachmentData);
  message.setContent(multipart);
  Transport.send(message);
  log.trace("Mail to {} was sent. Subj : {}, body : {}", to, subj, body);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the given plain text and HTML text as alternatives, offering
 * both options to the email client. Requires multipart mode.
 * <p><b>NOTE:</b> Invoke {@link #addInline} <i>after</i> {@code setText};
 * else, mail readers might not be able to resolve inline references correctly.
 * @param plainText the plain text for the message
 * @param htmlText the HTML text for the message
 * @throws MessagingException in case of errors
 */
public void setText(String plainText, String htmlText) throws MessagingException {
  Assert.notNull(plainText, "Plain text must not be null");
  Assert.notNull(htmlText, "HTML text must not be null");
  MimeMultipart messageBody = new MimeMultipart(MULTIPART_SUBTYPE_ALTERNATIVE);
  getMainPart().setContent(messageBody, CONTENT_TYPE_ALTERNATIVE);
  // Create the plain text part of the message.
  MimeBodyPart plainTextPart = new MimeBodyPart();
  setPlainTextToMimePart(plainTextPart, plainText);
  messageBody.addBodyPart(plainTextPart);
  // Create the HTML text part of the message.
  MimeBodyPart htmlTextPart = new MimeBodyPart();
  setHtmlTextToMimePart(htmlTextPart, htmlText);
  messageBody.addBodyPart(htmlTextPart);
}

代码示例来源: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: azkaban/azkaban

final Message message = sender.createMessage();
final InternetAddress from = new InternetAddress(this._fromAddress, false);
message.setFrom(from);
for (final String toAddr : this._toAddress) {
 message.addRecipient(Message.RecipientType.TO, new InternetAddress(
   toAddr, false));
   this._enableAttachementEmbedment ? new MimeMultipart("related")
     : new MimeMultipart();
 final BodyPart messageBodyPart = new MimeBodyPart();
 messageBodyPart.setContent(this._body.toString(), this._mimeType);
 multipart.addBodyPart(messageBodyPart);

代码示例来源:origin: stackoverflow.com

final Message msg = new MimeMessage(session);
   msg.setFrom(new InternetAddress(senderAddress, senderDisplayName));
   msg.addRecipient(Message.RecipientType.TO,
       new InternetAddress(m.getRecipient(), m.getRecipientDisplayName()));
   msg.setSubject(m.getSubject());
   // Unformatted text version
   final MimeBodyPart textPart = new MimeBodyPart();
   textPart.setContent(m.getText(), "text/plain"); 
   // HTML version
   final MimeBodyPart htmlPart = new MimeBodyPart();
   htmlPart.setContent(m.getHtml(), "text/html");
   // Create the Multipart.  Add BodyParts to it.
   final Multipart mp = new MimeMultipart("alternative");
   mp.addBodyPart(textPart);
   mp.addBodyPart(htmlPart);
   // Set Multipart as the message's content
   msg.setContent(mp);
   LOGGER.log(Level.FINEST, "Sending email {0}", m);
   Transport.send(msg);

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

/**
 * Adds message data and attachments.
 *
 * @param emailWithData {@link Email} with data
 * @param msgToSet      {@link MimeMessage} to set data into.
 * @throws MessagingException if there is a failure.
 */
private void addBodyData(final Email emailWithData, final MimeMessage msgToSet) throws MessagingException {
  final List<EmailMessage> messages = emailWithData.messages();
  final int totalMessages = messages.size();
  // Need to use new list since filterEmbeddedAttachments(List) removes attachments from the source List
  final List<EmailAttachment<? extends DataSource>> attachments = new ArrayList<>(emailWithData.attachments());
  if (attachments.isEmpty() && totalMessages == 1) {
    // special case: no attachments and just one content
    setContent(messages.get(0), msgToSet);
  } else {
    final MimeMultipart multipart = new MimeMultipart();
    final MimeMultipart msgMultipart = new MimeMultipart(ALTERNATIVE);
    multipart.addBodyPart(getBaseBodyPart(msgMultipart));
    for (final EmailMessage emailMessage : messages) {
      msgMultipart.addBodyPart(getBodyPart(emailMessage, attachments));
    }
    addAnyAttachments(attachments, multipart);
    msgToSet.setContent(multipart);
  }
}

代码示例来源:origin: stackoverflow.com

_auth = true; // smtp authentication - default on 
_multipart = new MimeMultipart(); 
 DataHandler handler = new DataHandler(new ByteArrayDataSource(_body.getBytes(), "text/plain")); 
 MimeMessage msg = new MimeMessage(session); 
 msg.setFrom(new InternetAddress(_from)); 
 msg.setDataHandler(handler);
 InternetAddress[] addressTo = new InternetAddress[_to.length]; 
 for (int i = 0; i < _to.length; i++) { 
  addressTo[i] = new InternetAddress(_to[i]);

代码示例来源:origin: stackoverflow.com

MimeMessage newMessage = new MimeMessage(session);
  MimeMultipart mimeMultipart = new MimeMultipart();
  MimeBodyPart attachment = new MimeBodyPart(is);
  attachment.setHeader("Content-Type", "contentType");
  mimeMultipart.addBodyPart(attachment);
  newMessage.setContent(mimeMultipart);
  newMessage.setFrom(InternetAddress.parse("fromAddress")[0]);
  newMessage.setReplyTo(InternetAddress.parse("toAddress"));
  newMessage.setSubject("subject");

代码示例来源:origin: stagemonitor/stagemonitor

/**
 * Creates a Multipart from present parts.
 * @return multipart with all present parts
 * @throws MessagingException
 */
private Multipart createMultiPart() throws MessagingException {
  Multipart multipart = new MimeMultipart("alternative");
  if (textPart != null) {
    // add text first, to give priority to html
    multipart.addBodyPart((BodyPart) createTextMimePart());
  }
  if (htmlPart != null) {
    multipart.addBodyPart((BodyPart) createHtmlMimePart());
  }
  return multipart;
}

代码示例来源:origin: stackoverflow.com

InternetAddress dests[] = new InternetAddress[emails.length];
for (int i = 0; i < emails.length; i++) {
  dests[i] = new InternetAddress(emails[i].trim().toLowerCase());
message.setSubject(subject, "UTF-8");
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(body, "text/html;charset=utf-8");
mp.addBodyPart(mbp);
message.setContent(mp);
message.setSentDate(new java.util.Date());

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

mimeText.setDataHandler(new DataHandler(new ByteArrayDataSource(
    Base64.encodeBase64(messageText.getBytes("UTF-8")), contentType + "; charset=\"utf-8\"")));
final MimeBodyPart mimeFile = new MimeBodyPart();
session.read(flowFile, new InputStreamCallback() {
  @Override
  public void process(final InputStream stream) throws IOException {
    try {
      mimeFile.setDataHandler(new DataHandler(new ByteArrayDataSource(stream, "application/octet-stream")));
    } catch (final Exception e) {
      throw new IOException(e);
MimeMultipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeText);
multipart.addBodyPart(mimeFile);

代码示例来源:origin: org.springframework/spring-context-support

break;
case MULTIPART_MODE_MIXED:
  MimeMultipart mixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
  mimeMessage.setContent(mixedMultipart);
  setMimeMultiparts(mixedMultipart, mixedMultipart);
  break;
case MULTIPART_MODE_RELATED:
  MimeMultipart relatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
  mimeMessage.setContent(relatedMultipart);
  setMimeMultiparts(relatedMultipart, relatedMultipart);
  break;
case MULTIPART_MODE_MIXED_RELATED:
  MimeMultipart rootMixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
  mimeMessage.setContent(rootMixedMultipart);
  MimeMultipart nestedRelatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
  MimeBodyPart relatedBodyPart = new MimeBodyPart();
  relatedBodyPart.setContent(nestedRelatedMultipart);
  rootMixedMultipart.addBodyPart(relatedBodyPart);

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

email_address = senderName + '<' + email_address + '>';
 msg.setFrom( new InternetAddress( email_address ) );
} else {
 throw new MessagingException( BaseMessages.getString( PKG, "Mail.Error.ReplyEmailNotFilled" ) );
  address[i] = new InternetAddress( reply_Address_List[i] );
InternetAddress[] address = new InternetAddress[destinations.length];
for ( int i = 0; i < destinations.length; i++ ) {
 address[i] = new InternetAddress( destinations[i] );
 messageText.append( Const.CR );
data.parts = new MimeMultipart();
MimeBodyPart part1 = new MimeBodyPart(); // put the text in the

代码示例来源:origin: log4j/log4j

part = new MimeBodyPart();
  part.setContent(s, layout.getContentType());
} else {
   headers.setHeader("Content-Type", layout.getContentType() + "; charset=UTF-8");
   headers.setHeader("Content-Transfer-Encoding", "quoted-printable");
   part = new MimeBodyPart(headers, os.toByteArray());
  } catch(Exception ex) {
    StringBuffer sbuf = new StringBuffer(s);
    part = new MimeBodyPart();
    part.setContent(sbuf.toString(), layout.getContentType());
Multipart mp = new MimeMultipart();
mp.addBodyPart(part);
msg.setContent(mp);

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

+ subjectType + '.');
setContent(body, toMsgString(t), "text/plain");
final MimeMultipart multipart = new MimeMultipart();
multipart.addBodyPart(body);
msg.setContent(multipart);
msg.setDescription(msgDesc);
setAcceptLang(msg);

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

/**
 * @param emailMessage {@link EmailMessage} with data.
 * @param attachments  {@link List} of {@link EmailAttachment}s.
 * @return new {@link MimeBodyPart} with data from emailMessage and attachments.
 * @throws MessagingException if there is a failure.
 */
private MimeBodyPart getBodyPart(final EmailMessage emailMessage, final List<EmailAttachment<? extends DataSource>> attachments) throws MessagingException {
  final MimeBodyPart bodyPart = new MimeBodyPart();
  // detect embedded attachments
  final List<EmailAttachment<? extends DataSource>> embeddedAttachments = filterEmbeddedAttachments(attachments, emailMessage);
  if (embeddedAttachments.isEmpty()) {
    // no embedded attachments, just add message
    setContent(emailMessage, bodyPart);
  } else {
    attachments.removeAll(embeddedAttachments);
    // embedded attachments detected, join them as related
    final MimeMultipart relatedMultipart = new MimeMultipart(RELATED);
    final MimeBodyPart messageData = new MimeBodyPart();
    setContent(emailMessage, messageData);
    relatedMultipart.addBodyPart(messageData);
    addAnyAttachments(embeddedAttachments, relatedMultipart);
    bodyPart.setContent(relatedMultipart);
  }
  return bodyPart;
}

代码示例来源:origin: stackoverflow.com

Multipart multipart = new MimeMultipart("mixed");
for (String str : attachment_PathList) {
  MimeBodyPart messageBodyPart = new MimeBodyPart();
  DataSource source = new FileDataSource(str);
  messageBodyPart.setDataHandler(new DataHandler(source));
  messageBodyPart.setFileName(source.getName());
  multipart.addBodyPart(messageBodyPart);
}
msg.setContent(multipart);
Transport.send(msg);

代码示例来源:origin: stackoverflow.com

Multipart _multipart = new MimeMultipart("test");
for (String str : attachment_List) {
  MimeBodyPart messageBodyPart = new MimeBodyPart();
  DataSource source = new FileDataSource(str);
  messageBodyPart.setDataHandler(new DataHandler(source));
  messageBodyPart.setFileName(source.getName());
  multipart.addBodyPart(messageBodyPart);
}
_msg.setContent(_multipart);
Transport.send(_msg);

代码示例来源:origin: voldemort/voldemort

MimeMultipart multiPartKeys = new MimeMultipart();
ByteArrayOutputStream keysOutputStream = new ByteArrayOutputStream();
  MimeBodyPart keyBody = new MimeBodyPart();
  try {
  MimeMultipart multiPartValues = new MimeMultipart();
  for(Versioned<byte[]> versionedValue: entry.getValue()) {
    MimeBodyPart valueBody = new MimeBodyPart();
    try {
message.setContent(multiPartKeys);
message.saveChanges();
try {

相关文章