当前位置: 首页>>代码示例>>Java>>正文


Java BodyPart.setContent方法代码示例

本文整理汇总了Java中javax.mail.BodyPart.setContent方法的典型用法代码示例。如果您正苦于以下问题:Java BodyPart.setContent方法的具体用法?Java BodyPart.setContent怎么用?Java BodyPart.setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.BodyPart的用法示例。


在下文中一共展示了BodyPart.setContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMessagePart

import javax.mail.BodyPart; //导入方法依赖的package包/类
private static Multipart getMessagePart() throws MessagingException, IOException {
    Multipart multipart = new MimeMultipart();
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText(getVal("msg.Body"));
    multipart.addBodyPart(messageBodyPart);
    if (getBoolVal("attach.reports")) {
        LOG.info("Attaching Reports as zip");
        multipart.addBodyPart(getReportsBodyPart());
    } else {
        if (getBoolVal("attach.standaloneHtml")) {
            multipart.addBodyPart(getStandaloneHtmlBodyPart());
        }
        if (getBoolVal("attach.console")) {
            multipart.addBodyPart(getConsoleBodyPart());
        }
        if (getBoolVal("attach.screenshots")) {
            multipart.addBodyPart(getScreenShotsBodyPart());
        }
    }
    messageBodyPart.setContent(getVal("msg.Body")
            .concat("\n\n\n")
            .concat(MailComponent.getHTMLBody()), "text/html");
    return multipart;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:25,代码来源:Mailer.java

示例2: sendAttachMail

import javax.mail.BodyPart; //导入方法依赖的package包/类
public boolean sendAttachMail(MailSenderInfo mailInfo) {
    MyAuthenticator authenticator = null;
    Properties pro = mailInfo.getProperties();
    if (mailInfo.isValidate()) {
        authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
    }
    try {
        Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
        mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
        mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(mailInfo.getToAddress()));
        mailMessage.setSubject(mailInfo.getSubject());
        mailMessage.setSentDate(new Date());
        Multipart multi = new MimeMultipart();
        BodyPart textBodyPart = new MimeBodyPart();
        textBodyPart.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
        multi.addBodyPart(textBodyPart);
        for (String path : mailInfo.getAttachFileNames()) {
            DataSource fds = new FileDataSource(path);
            BodyPart fileBodyPart = new MimeBodyPart();
            fileBodyPart.setDataHandler(new DataHandler(fds));
            fileBodyPart.setFileName(path.substring(path.lastIndexOf("/") + 1));
            multi.addBodyPart(fileBodyPart);
        }
        mailMessage.setContent(multi);
        mailMessage.saveChanges();
        Transport.send(mailMessage);
        return true;
    } catch (MessagingException ex) {
        ex.printStackTrace();
        return false;
    }
}
 
开发者ID:JamesLiAndroid,项目名称:AndroidKillerService,代码行数:33,代码来源:SimpleMailSender.java

示例3: buildEmailMessage

import javax.mail.BodyPart; //导入方法依赖的package包/类
private Message buildEmailMessage(EmailInfo emailInfo)
		throws AddressException, MessagingException, UnsupportedEncodingException {
	MimeMessage message = new MimeMessage(this.session);
	message.setFrom(new InternetAddress(emailInfo.getFrom(), "网页更新订阅系统", "UTF-8"));
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(emailInfo.getTo()));

	Multipart multipart = new MimeMultipart();
	BodyPart messageBodyPart = new MimeBodyPart();
	messageBodyPart.setContent(emailInfo.getContent(), "text/html;charset=UTF-8");
	multipart.addBodyPart(messageBodyPart);
	message.setContent(multipart);
	message.setSubject(emailInfo.getTitle());
	message.saveChanges();
	return message;
}
 
开发者ID:wrayzheng,项目名称:webpage-update-subscribe,代码行数:16,代码来源:EmailServer.java

示例4: sendEmail

import javax.mail.BodyPart; //导入方法依赖的package包/类
public void sendEmail() throws MessagingException {
  checkSettings();
  Properties props = new Properties();
  if (_usesAuth) {
    props.put("mail." + protocol + ".auth", "true");
    props.put("mail.user", _mailUser);
    props.put("mail.password", _mailPassword);
  } else {
    props.put("mail." + protocol + ".auth", "false");
  }
  props.put("mail." + protocol + ".host", _mailHost);
  props.put("mail." + protocol + ".timeout", _mailTimeout);
  props.put("mail." + protocol + ".connectiontimeout", _connectionTimeout);
  props.put("mail.smtp.starttls.enable", _tls);
  props.put("mail.smtp.ssl.trust", _mailHost);

  Session session = Session.getInstance(props, null);
  Message message = new MimeMessage(session);
  InternetAddress from = new InternetAddress(_fromAddress, false);
  message.setFrom(from);
  for (String toAddr : _toAddress)
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(
        toAddr, false));
  message.setSubject(_subject);
  message.setSentDate(new Date());

  if (_attachments.size() > 0) {
    MimeMultipart multipart =
        this._enableAttachementEmbedment ? new MimeMultipart("related")
            : new MimeMultipart();

    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setContent(_body.toString(), _mimeType);
    multipart.addBodyPart(messageBodyPart);

    // Add attachments
    for (BodyPart part : _attachments) {
      multipart.addBodyPart(part);
    }

    message.setContent(multipart);
  } else {
    message.setContent(_body.toString(), _mimeType);
  }

  // Transport transport = session.getTransport();

  SMTPTransport t = (SMTPTransport) session.getTransport(protocol);

  try {
    connectToSMTPServer(t);
  } catch (MessagingException ste) {
    if (ste.getCause() instanceof SocketTimeoutException) {
      try {
        // retry on SocketTimeoutException
        connectToSMTPServer(t);
        logger.info("Email retry on SocketTimeoutException succeeded");
      } catch (MessagingException me) {
        logger.error("Email retry on SocketTimeoutException failed", me);
        throw me;
      }
    } else {
      logger.error("Encountered issue while connecting to email server", ste);
      throw ste;
    }
  }
  t.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
  t.close();
}
 
开发者ID:JasonBian,项目名称:azkaban,代码行数:70,代码来源:EmailMessage.java

示例5: send

import javax.mail.BodyPart; //导入方法依赖的package包/类
public synchronized void send() throws Exception {
    MimeMessage message = new MimeMessage(session);
    DataHandler handler = new DataHandler(new ByteArrayDataSource(rxMailBuilder.getBody().getBytes(), rxMailBuilder.getType()));
    message.setFrom(new InternetAddress(rxMailBuilder.getUsername()));
    message.setSubject(rxMailBuilder.getSubject());

    message.setText(rxMailBuilder.getBody());
    message.setDataHandler(handler);
    if (_multipart.getCount() > 0) {
        BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setContent(rxMailBuilder.getBody(), rxMailBuilder.getType());
        _multipart.addBodyPart(messageBodyPart);
        message.setContent(_multipart);
    }
    if (rxMailBuilder.getMailTo().indexOf(',') > 0)
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(rxMailBuilder.getMailTo()));
    else
        message.setRecipient(Message.RecipientType.TO, new InternetAddress(rxMailBuilder.getMailTo()));
    Transport.send(message);
}
 
开发者ID:Lembed,项目名称:RxAndroidMail,代码行数:21,代码来源:RxMailSender.java

示例6: sendKindleMail

import javax.mail.BodyPart; //导入方法依赖的package包/类
private void sendKindleMail(AppUser user, byte[] attachment, String filename) throws MessagingException {
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText("Bookery delivery, frei haus!");

    BodyPart attachmentPart = new MimeBodyPart();
    attachmentPart.setFileName(filename + ".mobi");
    attachmentPart.setContent(attachment, "application/octet-stream");
    //attachmentPart.setDataHandler(new DataHandler(new ByteArrayDataSource(attachment, "application/x-mobipocket-ebook")));

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    multipart.addBodyPart(attachmentPart);

    MimeMessage message = new MimeMessage(mailSession);
    InternetAddress[] address = {new InternetAddress(user.geteMail())};
    message.setRecipients(Message.RecipientType.TO, address);
    message.setSubject("Bookery delivery");
    message.setSentDate(new Date());
    message.setContent(multipart);

    Transport.send(message);
}
 
开发者ID:felixhusse,项目名称:bookery,代码行数:23,代码来源:BookeryMailService.java

示例7: appendIcsBody

import javax.mail.BodyPart; //导入方法依赖的package包/类
protected MimeMessage appendIcsBody(MimeMessage msg, MailMessage m) throws Exception {
	log.debug("setMessageBody for iCal message");
	// -- Create a new message --
	Multipart multipart = new MimeMultipart();

	Multipart multiBody = new MimeMultipart("alternative");
	BodyPart html = new MimeBodyPart();
	html.setDataHandler(new DataHandler(new ByteArrayDataSource(m.getBody(), "text/html; charset=UTF-8")));
	multiBody.addBodyPart(html);

	BodyPart iCalContent = new MimeBodyPart();
	iCalContent.addHeader("content-class", "urn:content-classes:calendarmessage");
	iCalContent.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(m.getIcs()),
			"text/calendar; charset=UTF-8; method=REQUEST")));
	multiBody.addBodyPart(iCalContent);
	BodyPart body = new MimeBodyPart();
	body.setContent(multiBody);
	multipart.addBodyPart(body);

	BodyPart iCalAttachment = new MimeBodyPart();
	iCalAttachment.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(m.getIcs()),
			"application/ics")));
	iCalAttachment.removeHeader("Content-Transfer-Encoding");
	iCalAttachment.addHeader("Content-Transfer-Encoding", "base64");
	iCalAttachment.removeHeader("Content-Type");
	iCalAttachment.addHeader("Content-Type", "application/ics");
	iCalAttachment.setFileName("invite.ics");
	multipart.addBodyPart(iCalAttachment);

	msg.setContent(multipart);
	return msg;
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:33,代码来源:MailHandler.java

示例8: encode

import javax.mail.BodyPart; //导入方法依赖的package包/类
public Message encode(Mail mail) {
	try {
		// 根据session创建一个邮件消息
		Message message = new MimeMessage(Session.getDefaultInstance(getSesstionProperties(), new MailAuth(userName, password)));
		// 创建邮件发送者地址
		Address from = new InternetAddress(mail.getFromAddress(), personal, CoreDef.CHARSET());
		// 设置邮件消息的发送者
		message.setFrom(from);
		// 创建邮件的接收者地址,并设置到邮件消息中
		Address to = new InternetAddress(mail.getToAddress());
		message.setRecipient(Message.RecipientType.TO, to);
		// 设置邮件消息的主题
		message.setSubject(mail.getSubject());
		// 设置邮件消息发送的时间
		message.setSentDate(new Date());

		if (!mail.isPlainText()) {
			// MiniMultipart类是一个容器类,包含MimeBodyPart类型的对象
			Multipart mainPart = new MimeMultipart();
			// 创建一个包含HTML内容的MimeBodyPart
			BodyPart html = new MimeBodyPart();
			// 设置HTML内容
			html.setContent(mail.getContent(), "text/html;charset=utf-8");
			mainPart.addBodyPart(html);
			// 将MiniMultipart对象设置为邮件内容
			message.setContent(mainPart);
		} else {
			// 设置邮件消息的主要内容
			message.setText(mail.getContent());
		}
		return message;
	} catch (Exception e) {
		throw new LYException("Encode mail message failed", e);
	}
}
 
开发者ID:liyang-bsy,项目名称:LYLab,代码行数:36,代码来源:MailSender.java

示例9: setBody

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * 设置邮件内容,并设置其为文本格式或HTML文件格式,编码方式为UTF-8
 * 
 * @param mailBody
 * @return
 */
public static boolean setBody(String mailBody) {
	try {
		BodyPart bp = new MimeBodyPart();
		bp.setContent(
				"<meta http-equiv=Content-Type content=text/html; charset=UTF-8>"
						+ mailBody, "text/html;charset=UTF-8");
		mp.addBodyPart(bp);
	} catch (Exception e) {
		return false;
	}
	return true;
}
 
开发者ID:839536,项目名称:kettle,代码行数:19,代码来源:Message.java

示例10: sendHtmlMail

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * 以HTML格式发送邮件.
 *
 * @param mailSender 待发送的邮件信息
 * @return Boolean
 */
protected boolean sendHtmlMail(final AbstractMailSender mailSender) {
    final Properties pro = mailSender.getProperties();
    MailAuthenticator authenticator = null;
    if (mailSender.isValidate()) {
        authenticator = new MailAuthenticator(mailSender.getUserName(), mailSender.getPassword());
    }

    final Session sendMailSession;
    if(singletonSessionInstance) {
        sendMailSession = Session.getDefaultInstance(pro, authenticator);
    } else {
        sendMailSession = Session.getInstance(pro, authenticator);
    }
    
    sendMailSession.setDebug(debugEnabled);
    try {
        final Message mailMessage = new MimeMessage(sendMailSession);
        final Address from = new InternetAddress(mailSender.getFromAddress());
        mailMessage.setFrom(from);
        mailMessage.setRecipients(Message.RecipientType.TO, toAddresses(mailSender.getToAddress()));
        mailMessage.setSubject(mailSender.getSubject());
        mailMessage.setSentDate(new Date());
        final Multipart mainPart = new MimeMultipart();
        final BodyPart html = new MimeBodyPart();
        html.setContent(mailSender.getContent(), "text/html; charset=utf-8");
        mainPart.addBodyPart(html);
        mailMessage.setContent(mainPart);
        Transport.send(mailMessage);
        return true;
    } catch (final MessagingException ex) {
        LOGGER.error(ex.getMessage(), ex);
    }
    
    return false;
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:42,代码来源:AbstractMailSenderFactory.java

示例11: prepareHTMLMimeMessage

import javax.mail.BodyPart; //导入方法依赖的package包/类
private MimeMessage prepareHTMLMimeMessage(InternetAddress internetAddressFrom,String subject,String htmlBody,List<LabelValueBean> attachments) throws Exception {
	MimeMessage msg = new MimeMessage(session);
	msg.setFrom(internetAddressFrom);
	msg.setHeader(XMAILER, xmailer);
	msg.setSubject(subject.trim(), mailEncoding );
	msg.setSentDate(new Date());

	MimeMultipart mimeMultipart = new MimeMultipart("related");

	BodyPart messageBodyPart = new MimeBodyPart();
	//Euro sign finally, shown correctly
	messageBodyPart.setContent(htmlBody, "text/html;charset="+mailEncoding);
	mimeMultipart.addBodyPart(messageBodyPart);

	if(attachments!=null && !attachments.isEmpty()){
		LOGGER.debug("Use attachments: "+attachments.size());
		includeAttachments(mimeMultipart,attachments);
	}

	msg.setContent(mimeMultipart);

	return msg;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:24,代码来源:MailBuilder.java

示例12: send

import javax.mail.BodyPart; //导入方法依赖的package包/类
public Result<String> send(String subject, String text, String... sendTo) {
      if (sendTo == null || sendTo.length == 0) {
        return Result.success("no-to");
      }

      try {
        // From
        message.setFrom(this.from);
        // 宛先(TO)
        List<InternetAddress> tos = new ArrayList<>();
        for (String address : sendTo) {
          tos.add(new InternetAddress(address));
        }
        message.setRecipients(MimeMessage.RecipientType.TO, tos.toArray(new InternetAddress[0]));

        // 件名および本文
        message.setSubject(subject, "ISO-2022-JP");

        Multipart multiPart = new MimeMultipart();
        BodyPart html = new MimeBodyPart();
        html.setContent(text, "text/html; charset=utf-8");
        multiPart.addBodyPart(html);
        message.setContent(multiPart);
//        message.setText(text, "ISO-2022-JP");

        Transport.send(message);
      } catch (MessagingException e) {
        throw new RuntimeException(e);
      }

      return Result.success("ok");
    }
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:33,代码来源:MailSender.java

示例13: sendHTML

import javax.mail.BodyPart; //导入方法依赖的package包/类
public void sendHTML(Mailable email) throws MessagingException {
    Session mailSession = Session.getInstance(this.mailConfig, null);
    MimeMessage message = new MimeMessage(mailSession);
    MimeMultipart multipart = new MimeMultipart("alternative");
    BodyPart bp = new MimeBodyPart();
    bp.setContent(email.getMessage(), "text/plain; charset=UTF-8");
    BodyPart bp2 = new MimeBodyPart();
    bp2.setContent(email.getMessage(), "text/html; charset=UTF-8");
    
    multipart.addBodyPart(bp2);
    multipart.addBodyPart(bp);
    message.setContent(multipart);
    message.setSentDate(new java.util.Date());
    message.setFrom(new InternetAddress(email.getSender()));
    message.setSubject(email.getSubject());
    //FIXME if more than one recipient break it appart before setting the recipient field
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(email.getRecipients()));
    Transport.send(message);
}
 
开发者ID:DIA-NZ,项目名称:webcurator,代码行数:20,代码来源:MailServerImpl.java

示例14: setBody

import javax.mail.BodyPart; //导入方法依赖的package包/类
private boolean setBody(String mailBody) {
		try {
			BodyPart bp = new MimeBodyPart();
			bp.setContent("" + mailBody, "text/html;charset=GBK");
			mp.addBodyPart(bp);
			return true;
		} catch (Exception e) {
//			System.err.println("定义邮件正文时发生错误!" + e);
			return false;
		}
	}
 
开发者ID:RangerWolf,项目名称:Finance-News-Helper,代码行数:12,代码来源:EMailUtils.java

示例15: buildEnrichedMimeMessage

import javax.mail.BodyPart; //导入方法依赖的package包/类
private String buildEnrichedMimeMessage(String enrichedSOAPMessage) throws MessagingException, IOException {
    for (int i=0; i<mimeMessage.getCount(); i++) {
        BodyPart part = mimeMessage.getBodyPart(i);
        if (part.getContentType().contains("application/soap+xml")) {
            Enumeration copyOfHeaders = createCopyOfHeaders(part);
            part.setContent(enrichedSOAPMessage, part.getContentType());
            copyHeadersToPart(copyOfHeaders, part);
            break;
        }
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    mimeMessage.writeTo(out);
    mimeMessage = null;
    return out.toString();
}
 
开发者ID:jembi,项目名称:openhim-mediator-xds,代码行数:17,代码来源:XDSbMimeProcessorActor.java


注:本文中的javax.mail.BodyPart.setContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。