當前位置: 首頁>>代碼示例>>Java>>正文


Java MimeBodyPart.setText方法代碼示例

本文整理匯總了Java中javax.mail.internet.MimeBodyPart.setText方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeBodyPart.setText方法的具體用法?Java MimeBodyPart.setText怎麽用?Java MimeBodyPart.setText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.internet.MimeBodyPart的用法示例。


在下文中一共展示了MimeBodyPart.setText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendMultiPartEmail

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
private void sendMultiPartEmail(String from, String to, String subject, String body) throws MessagingException {
    Properties props = createEmailProps(serverPort);
    Session session = Session.getInstance(props);

    Message msg = createBaseMessage(from, to, subject, session);

    MimeBodyPart p1 = new MimeBodyPart();
    p1.setText(body);

    MimeBodyPart p2 = new MimeBodyPart();
    p2.setText("Second part");

    Multipart mp = new MimeMultipart();
    mp.addBodyPart(p1);
    mp.addBodyPart(p2);

    msg.setContent(mp);

    Transport.send(msg);
}
 
開發者ID:anlar,項目名稱:LunaticSMTP,代碼行數:21,代碼來源:ServerTest.java

示例2: addPart

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
/**
 * Add a part with the specified text to the specified position
 *
 * @param content the part's content
 * @param contentTypeSubtype the part's subtype of content type like plain (sub type of text/plain) or html (sub type of text/html)
 * @param charset the part's charset
 * @throws PackageException
 */
@PublicAtsApi
public void addPart(
                     String content,
                     String contentTypeSubtype,
                     String charset ) throws PackageException {

    // create a new inline part
    MimeBodyPart part = new MimeBodyPart();

    try {
        part.setText(content, charset, contentTypeSubtype);
        part.setDisposition(MimeBodyPart.INLINE);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }

    addPart(part, PART_POSITION_LAST);
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:27,代碼來源:MimePackage.java

示例3: addAttachment

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
/**
 * Add an attachment with the specified content - the attachment will have a
 * content type text\plain and the specified character set
 *
 * @param content
 *            the content of the attachment
 * @param charset
 *            the character set
 * @param fileName
 *            the file name for the content-disposition header
 * @throws PackageException
 *             on error
 */
@PublicAtsApi
public void addAttachment(
                           String content,
                           String charset,
                           String fileName ) throws PackageException {

    try {
        // add attachment to multipart content
        MimeBodyPart attPart = new MimeBodyPart();
        attPart.setText(content, charset, PART_TYPE_TEXT_PLAIN);
        attPart.setDisposition(MimeBodyPart.ATTACHMENT);
        attPart.setFileName(fileName);

        addPart(attPart, PART_POSITION_LAST);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:32,代碼來源:MimePackage.java

示例4: createMimeMessageWithHtml

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
public static MimeMessage createMimeMessageWithHtml(Session session) throws MessagingException, AddressException {
  MimeMessage message = createMimeMessage(session);

  Multipart multiPart = new MimeMultipart();

  MimeBodyPart textPart = new MimeBodyPart();
  textPart.setText("text");
  multiPart.addBodyPart(textPart);

  MimeBodyPart htmlPart = new MimeBodyPart();
  htmlPart.setContent("<b>html</b>", MailContentType.TEXT_HTML.getType());
  multiPart.addBodyPart(htmlPart);

  message.setContent(multiPart);
  return message;
}
 
開發者ID:camunda,項目名稱:camunda-bpm-mail,代碼行數:17,代碼來源:MailTestUtil.java

示例5: createMimeMessageWithAttachment

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
public static MimeMessage createMimeMessageWithAttachment(Session session, File attachment) throws MessagingException, AddressException, IOException {
  MimeMessage message = createMimeMessage(session);

  Multipart multiPart = new MimeMultipart();

  MimeBodyPart textPart = new MimeBodyPart();
  textPart.setText("text");
  multiPart.addBodyPart(textPart);

  MimeBodyPart filePart = new MimeBodyPart();
  filePart.attachFile(attachment);
  multiPart.addBodyPart(filePart);

  message.setContent(multiPart);

  return message;
}
 
開發者ID:camunda,項目名稱:camunda-bpm-mail,代碼行數:18,代碼來源:MailTestUtil.java

示例6: getTextBodyPart

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
private MimeBodyPart getTextBodyPart(String bodyText, String subtype, String mimeType) throws MessagingException
{
    MimeBodyPart result = new MimeBodyPart();
    result.setText(bodyText, AlfrescoImapConst.UTF_8, subtype);
    result.addHeader(AlfrescoImapConst.CONTENT_TYPE, mimeType + AlfrescoImapConst.CHARSET_UTF8);
    result.addHeader(AlfrescoImapConst.CONTENT_TRANSFER_ENCODING, AlfrescoImapConst.BASE_64_ENCODING);
    return result;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:9,代碼來源:ContentModelMessage.java

示例7: addAlternativePart

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
/**
 * Add a multipart/alternative part to message body
 *
 * @param plainContent
 *            the content of the text/plain sub-part
 * @param htmlContent
 *            the content of the text/html sub-part
 * @param charset
 *            the character set for the part
 * @throws PackageException
 */
@PublicAtsApi
public void addAlternativePart(
                                String plainContent,
                                String htmlContent,
                                String charset ) throws PackageException {

    MimeMultipart alternativePart = new MimeMultipart("alternative");

    try {
        // create a new text/plain part
        MimeBodyPart plainPart = new MimeBodyPart();
        plainPart.setText(plainContent, charset, PART_TYPE_TEXT_PLAIN);
        plainPart.setDisposition(MimeBodyPart.INLINE);

        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setText(htmlContent, charset, PART_TYPE_TEXT_HTML);
        htmlPart.setDisposition(MimeBodyPart.INLINE);

        alternativePart.addBodyPart(plainPart, 0);
        alternativePart.addBodyPart(htmlPart, 1);

        MimeBodyPart mimePart = new MimeBodyPart();
        mimePart.setContent(alternativePart);

        addPart(mimePart, PART_POSITION_LAST);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:41,代碼來源:MimePackage.java

示例8: createEmailWithAttachment

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
public static MimeMessage createEmailWithAttachment(String to, String from, String subject,
                                      String bodyText,String filePath) throws MessagingException{
    File file = new File(filePath);
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    MimeMessage email = new MimeMessage(session);
    Multipart multipart = new MimeMultipart();
    InternetAddress tAddress = new InternetAddress(to);
    InternetAddress fAddress = new InternetAddress(from);
    email.setFrom(fAddress);
    email.addRecipient(javax.mail.Message.RecipientType.TO, tAddress);
    email.setSubject(subject);
    if (file.exists()) {
        source = new FileDataSource(filePath);
        messageFilePart = new MimeBodyPart();
        messageBodyPart = new MimeBodyPart();
        try {
            messageBodyPart.setText(bodyText);
            messageFilePart.setDataHandler(new DataHandler(source));
            messageFilePart.setFileName(file.getName());

            multipart.addBodyPart(messageBodyPart);
            multipart.addBodyPart(messageFilePart);
            email.setContent(multipart);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }else
        email.setText(bodyText);
    return email;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:32,代碼來源:EmailShield.java

示例9: createMessageContent

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
protected void createMessageContent(Message message, SendMailRequest request) throws MessagingException, IOException {
  if (isTextOnlyMessage(request)) {
    message.setText(request.getText());

  } else {
    Multipart multiPart = new MimeMultipart();

    if (request.getText() != null) {
      MimeBodyPart textPart = new MimeBodyPart();
      textPart.setText(request.getText());
      multiPart.addBodyPart(textPart);
    }

    if (request.getHtml() != null) {
      MimeBodyPart htmlPart = new MimeBodyPart();
      htmlPart.setContent(request.getHtml(), MailContentType.TEXT_HTML.getType());
      multiPart.addBodyPart(htmlPart);
    }

    if (request.getFileNames() != null) {
      for (String fileName : request.getFileNames()) {
        MimeBodyPart part = new MimeBodyPart();
        part.attachFile(fileName);
        multiPart.addBodyPart(part);
      }
    }

    message.setContent(multiPart);
  }
}
 
開發者ID:camunda,項目名稱:camunda-bpm-mail,代碼行數:31,代碼來源:SendMailConnector.java

示例10: createMultipartAlternativeMessage

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
protected void createMultipartAlternativeMessage(MimeMessage mimeMessage, MailConfiguration configuration, Exchange exchange)
    throws MessagingException, IOException {

    MimeMultipart multipartAlternative = new MimeMultipart("alternative");
    mimeMessage.setContent(multipartAlternative);

    MimeBodyPart plainText = new MimeBodyPart();
    plainText.setText(getAlternativeBody(configuration, exchange), determineCharSet(configuration, exchange));
    // remove the header with the alternative mail now that we got it
    // otherwise it might end up twice in the mail reader
    exchange.getIn().removeHeader(configuration.getAlternativeBodyHeader());
    multipartAlternative.addBodyPart(plainText);

    // if there are no attachments, add the body to the same mulitpart message
    if (!exchange.getIn().hasAttachments()) {
        addBodyToMultipart(configuration, multipartAlternative, exchange);
    } else {
        // if there are attachments, but they aren't set to be inline, add them to
        // treat them as normal. It will append a multipart-mixed with the attachments and the body text
        if (!configuration.isUseInlineAttachments()) {
            BodyPart mixedAttachments = new MimeBodyPart();
            mixedAttachments.setContent(createMixedMultipartAttachments(configuration, exchange));
            multipartAlternative.addBodyPart(mixedAttachments);
        } else {
            // if the attachments are set to be inline, attach them as inline attachments
            MimeMultipart multipartRelated = new MimeMultipart("related");
            BodyPart related = new MimeBodyPart();

            related.setContent(multipartRelated);
            multipartAlternative.addBodyPart(related);

            addBodyToMultipart(configuration, multipartRelated, exchange);
            AttachmentsContentTransferEncodingResolver resolver = configuration.getAttachmentsContentTransferEncodingResolver();
            addAttachmentsToMultipart(multipartRelated, Part.INLINE, resolver, exchange);
        }
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:38,代碼來源:MailBinding.java

示例11: sendAttachmentEmail

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
public static void sendAttachmentEmail(String to, String from, String subject, String msg, final byte[] attachment, final String contentType, final String filename, final String description, final ServerSetup setup) throws MessagingException, IOException {
    Session session = getSession(setup);

    Address[] tos = new InternetAddress[]{new InternetAddress(to)};
    Address[] froms = new InternetAddress[]{new InternetAddress(from)};
    MimeMessage mimeMessage = new MimeMessage(session);
    mimeMessage.setSubject(subject);
    mimeMessage.setFrom(froms[0]);

    MimeMultipart multiPart = new MimeMultipart();

    MimeBodyPart textPart = new MimeBodyPart();
    multiPart.addBodyPart(textPart);
    textPart.setText(msg);

    MimeBodyPart binaryPart = new MimeBodyPart();
    multiPart.addBodyPart(binaryPart);

    DataSource ds = new DataSource() {
        public InputStream getInputStream() throws IOException {
            return new ByteArrayInputStream(attachment);
        }

        public OutputStream getOutputStream() throws IOException {
            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
            byteStream.write(attachment);
            return byteStream;
        }

        public String getContentType() {
            return contentType;
        }

        public String getName() {
            return filename;
        }
    };
    binaryPart.setDataHandler(new DataHandler(ds));
    binaryPart.setFileName(filename);
    binaryPart.setDescription(description);

    mimeMessage.setContent(multiPart);
    Transport.send(mimeMessage, tos);
}
 
開發者ID:Alfresco,項目名稱:alfresco-greenmail,代碼行數:45,代碼來源:GreenMailUtil.java

示例12: send

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
public void send(String text, String attachment) throws Exception {
	Session session = Session.getInstance(props, new Authenticator() {

		@Override
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(props.getProperty("mail.smtp.user"), props
					.getProperty("mail.smtp.password"));
		}

	});

	if (from == null)
		from = props.getProperty("mail.from");
	if (to == null)
		to = props.getProperty("mail.to");
	if (cc == null)
		cc = props.getProperty("mail.cc");
	if (bcc == null)
		bcc = props.getProperty("mail.bcc");
	if (subject == null)
		subject = props.getProperty("mail.subject");

	Message msg = new MimeMessage(session);

	msg.setFrom(new InternetAddress(from));
	msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
	if (cc != null)
		msg.setRecipient(Message.RecipientType.CC, new InternetAddress(cc));
	if (bcc != null)
		msg.setRecipient(Message.RecipientType.BCC, new InternetAddress(bcc));

	msg.setSubject(subject);
	msg.setSentDate(new Date());

	if (attachment != null) {
		MimeBodyPart tp = new MimeBodyPart();
		tp.setText(text);

		MimeBodyPart ap = new MimeBodyPart();
		FileDataSource fds = new FileDataSource(attachment);
		ap.setDataHandler(new DataHandler(fds));
		ap.setFileName(fds.getName());

		Multipart mp = new MimeMultipart();
		mp.addBodyPart(tp);
		mp.addBodyPart(ap);

		msg.setContent(mp);
	} else {
		msg.setText(text);
	}

	Transport.send(msg);

	Logs.debug("Have sent an email notification to {}. ", to);
}
 
開發者ID:xiaojieliu7,項目名稱:MicroServiceProject,代碼行數:57,代碼來源:EMailer.java

示例13: makeBodyPart

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
private MimeBodyPart makeBodyPart(TokenData data, _EmailTemplateContent template, _BridgeMessageContent content) throws IOException, MessagingException {
    StringBuilder partRaw = new StringBuilder();

    String header = processToken(data, template.getHeader());
    String footer = processToken(data, template.getFooter());
    String contentString = processToken(data, template.getContent(), content.getContentAsString());

    partRaw.append(header).append(contentString).append(footer);

    MimeBodyPart part = new MimeBodyPart();
    part.setText(partRaw.toString(), StandardCharsets.UTF_8.name(), template.getType().replace("text/", ""));

    log.info("Created body part of type {}", template.getType());

    return part;
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:17,代碼來源:EmailFormatterOutboud.java

示例14: sendEmail

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
/**
 * <p>Send email.</p>
 * @param pAddParam additional param
 * @param pMsg msg to mail
 * @throws Exception - an exception
 **/
@Override
public final void sendEmail(final Map<String, Object> pAddParam,
  final EmailMsg pMsg) throws Exception {
  Properties props = new Properties();
  for (EmailStringProperty esp
    : pMsg.getEmailConnect().getStringProperties()) {
    props.put(esp.getPropertyName(), esp.getPropretyValue());
  }
  for (EmailIntegerProperty eip
    : pMsg.getEmailConnect().getIntegerProperties()) {
    props.put(eip.getPropertyName(), eip.getPropretyValue());
  }
  Session sess = Session.getInstance(props);
  Message msg = new MimeMessage(sess);
  msg.setFrom(new InternetAddress(pMsg.getEmailConnect().getUserEmail()));
  if (pMsg.getErecipients().size() == 1) {
    msg.setRecipient(Message.RecipientType.TO,
      new InternetAddress(pMsg.getErecipients().get(0).getItsEmail()));
  } else {
    InternetAddress[] address =
      new InternetAddress[pMsg.getErecipients().size()];
    for (int i = 0; i < pMsg.getErecipients().size(); i++) {
      address[i] = new InternetAddress(pMsg.getErecipients().get(i)
        .getItsEmail());
    }
    msg.setRecipients(Message.RecipientType.TO, address);
  }
  msg.setSubject(pMsg.getEsubject());
  if (pMsg.getEattachments().size() > 0) {
    MimeBodyPart mbpt = new MimeBodyPart();
    mbpt.setText(pMsg.getEtext());
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbpt);
    for (Eattachment attch : pMsg.getEattachments()) {
      MimeBodyPart mbp = new MimeBodyPart();
      mbp.attachFile(attch.getItsPath());
      mp.addBodyPart(mbp);
    }
    msg.setContent(mp);
  } else {
    msg.setText(pMsg.getEtext());
  }
  msg.setSentDate(new Date());
  Transport.send(msg, pMsg.getEmailConnect().getUserEmail(),
    pMsg.getEmailConnect().getUserPassword());
}
 
開發者ID:demidenko05,項目名稱:beige-software,代碼行數:53,代碼來源:MailSenderStd.java

示例15: buildTextBodyPart

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
private MimeBodyPart buildTextBodyPart() throws MessagingException {
    final MimeBodyPart textPart = new MimeBodyPart();
    textPart.setText(text, "utf-8");
    return textPart;
}
 
開發者ID:blackducksoftware,項目名稱:hub-email-extension,代碼行數:6,代碼來源:MimeMultipartBuilder.java


注:本文中的javax.mail.internet.MimeBodyPart.setText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。