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


Java MimeMessage.setSender方法代码示例

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


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

示例1: buildMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private MimeMessage buildMail(MimeMessage message) {
	MimeMessage ret = message;
	try {
		Address[] replies = {new InternetAddress(sSender)};
		String[] recipients = sRecipients.split(",|;");
		// Adding sender
		ret.setFrom(new InternetAddress(sSender));
		ret.setSender(new InternetAddress(sSender));
		ret.setReplyTo(replies);
		
		//Adding recipients
		if (recipients[0].indexOf(":") != -1) {
			ret.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients[0].split(":")[1]));
		} else {
			ret.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients[0]));
		}
		for (int i = 1; i < recipients.length; i++) {
			if (recipients[i].indexOf(":") != -1) {
				String sRecipientType  = recipients[i].split(":")[0];
				String sRecipientAddress  = recipients[i].split(":")[1];
				if ("TO".equalsIgnoreCase(sRecipientType)) {
					ret.addRecipient(Message.RecipientType.TO, new InternetAddress(sRecipientAddress));
				} else if ("BCC".equalsIgnoreCase(sRecipientType)) {
					ret.addRecipient(Message.RecipientType.BCC, new InternetAddress(sRecipientAddress));
				} else {
					ret.addRecipient(Message.RecipientType.CC, new InternetAddress(sRecipientAddress));
				}
			} else {
				ret.addRecipient(Message.RecipientType.CC, new InternetAddress(recipients[i]));
			}
		}

		//Add receipts
		if (getDeliveryReceipt()) {
			message.setHeader("Return-Receipt-To", new InternetAddress(sSender).toString());
		}
		if (getReadReceipt()) {
			message.setHeader("Disposition-Notification-To", new InternetAddress(sSender).toString());
		}
		
		
		//Adding mail subject
		ret.setSubject(sSubject);

		//Adding content
		if (bodyParts.size() > 0) {
			Multipart multipart = new MimeMultipart();
			
			MimeBodyPart msgPart = new MimeBodyPart();
			msgPart.setContent(sMessageText, sContentType);
			multipart.addBodyPart(msgPart);
			
			for (BodyPart bodyPart : bodyParts) {
				multipart.addBodyPart(bodyPart);
			}
			
			ret.setContent(multipart);
		} else {
			ret.setContent(sMessageText, sContentType);
		}
	} catch (Exception e1) {
		Engine.logBeans.error("(SmtpStep) An error occured while trying to build e-mail : " + e1.getStackTrace().toString(), e1);
	}
	return ret;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:66,代码来源:SmtpStep.java


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