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


Java MimeMessageHelper.addTo方法代码示例

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


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

示例1: prepareEmail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private int prepareEmail(MimeMessage mimeMessage, String subject, String emailAddresses) throws Exception {
	int toCount = 0;
	if (!CommonUtil.isEmptyString(emailAddresses)) {
		MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false, EMAIL_ENCODING);
		mimeMessageHelper.setSubject(subject);
		mimeMessageHelper.setText(output.toString());
		mimeMessageHelper.setFrom(Settings.getEmailExecFromAddress(), Settings.getEmailExecFromName());
		String[] addresses = emailAddressSeparatorRegexp.split(emailAddresses, -1);
		for (int i = 0; i < addresses.length; i++) {
			if (!CommonUtil.isEmptyString(addresses[i])) {
				mimeMessageHelper.addTo(addresses[i].trim());
				toCount++;
			}
		}
	}
	return toCount;
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:18,代码来源:JobOutput.java

示例2: sendText

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private void sendText(final String subject, final String nonHtml) {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true);
            messageHelper.setValidateAddresses(true);

            String[] split = to_commaseparated.split(",");
            for (String emailAddress : split) {
                emailAddress = emailAddress.trim();
                try {
                    log.trace("adding " + emailAddress);
                    messageHelper.addTo(emailAddress);
                    log.trace("added " + emailAddress);
                } catch (MessagingException e) {
                    log.error("unable to parse email address from " + emailAddress, e);
                }
            }
            messageHelper.setFrom(from);
            messageHelper.setSubject(subject);
            messageHelper.setText(nonHtml, false);
        }
    };
    javaMailSender.send(preparator);
}
 
开发者ID:trifork,项目名称:HAIBA-EPIMIBA-classification,代码行数:26,代码来源:EmailSender.java

示例3: prepare

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
protected int prepare(MimeMessage mimeMessage, Notification notification, Staff recipient) throws Exception {
	if (!Settings.getBoolean(SettingCodes.EMAIL_NOTIFICATIONS_ENABLED, Bundle.SETTINGS, DefaultSettings.EMAIL_NOTIFICATIONS_ENABLED)) {
		return 0;
	}
	MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false, EMAIL_ENCODING);
	String subject = notification.getSubject();
	String text = notification.getMessage();
	if (!CommonUtil.isEmptyString(subject)) {
		mimeMessageHelper.setSubject(subject);
	} else {
		return 0;
	}
	if (!CommonUtil.isEmptyString(text)) {
		mimeMessageHelper.setText(text);
	} else {
		return 0;
	}
	mimeMessageHelper.setFrom(Settings.getEmailNotificationFromAddress(), Settings.getEmailNotificationFromName());
	StaffOutVO recipientVO = staffDao.toStaffOutVO(recipient);
	int toCount = 0;
	Iterator<StaffContactDetailValue> contactsIt = recipient.getContactDetailValues().iterator();
	while (contactsIt.hasNext()) {
		StaffContactDetailValue contact = contactsIt.next();
		ContactDetailType contactType;
		if (!contact.isNa() && contact.isNotify() && (contactType = contact.getType()).isEmail()) {
			mimeMessageHelper.addTo(contact.getValue(),
					MessageFormat.format(EMAIL_TO_PERSONAL_NAME, recipientVO.getName(), L10nUtil.getContactDetailTypeName(Locales.NOTIFICATION, contactType.getNameL10nKey())));
			toCount++;
		}
	}
	return toCount;
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:34,代码来源:NotificationEmailSender.java

示例4: addTo

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private void addTo(MimeMessageHelper message, String emailAddress, String personalName)
        throws MessagingException, UnsupportedEncodingException {
    if (personalName == null) {
        message.addTo(emailAddress);
    } else {
        message.addTo(emailAddress, personalName);
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:9,代码来源:VelocityMimeMessagePreparator.java

示例5: send

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
protected void send() throws Exception {
  try (ClosableSmtpConnection connection = smtpConnectionPool.borrowObject()) {
    MimeMessage mimeMessage = new MimeMessage(connection.getSession());
    MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false);
    mimeMessageHelper.addTo("[email protected]");
    mimeMessageHelper.setFrom("[email protected]");
    mimeMessageHelper.setSubject("foo");
    mimeMessageHelper.setText("example", false);
    connection.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
  }
}
 
开发者ID:nithril,项目名称:smtp-connection-pool,代码行数:12,代码来源:AbstractTest.java

示例6: sendMailWithAttachments

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
public void sendMailWithAttachments(final TemplateWithAttachmentMailTO template) throws MailException {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true);

            message.addTo(template.getToMailAddress());
            message.setFrom(template.getFromMailAddress());
            message.setSubject(template.getSubject());
            if (template.hasCcMailAddress()) {
                message.setCc(template.getCcMailAddress());
            }
            if (template.hasReplyTo()) {
                message.setReplyTo(template.getReplyTo());
            }

            // add attachments if any
            List<File> attachments = template.getAttachments();
            for (File file : attachments) {
                message.addAttachment(file.getName(), file);
            }

            String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, template.getTemplateLocation(), template.getTemplateProperties());
            message.setText(text, true);
            message.setValidateAddresses(true);
        }
    };
    this.mailSender.send(preparator);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:31,代码来源:MailServiceImpl.java

示例7: createMimeMessage

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private MimeMessage createMimeMessage() throws MessagingException {
    MimeMessage message = new MimeMessage(Session.getInstance(new Properties()));
    MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(message);
    mimeMessageHelper.addTo("[email protected]");
    mimeMessageHelper.setText("body text");
    mimeMessageHelper.setSubject("subject");
    mimeMessageHelper.getMimeMessage().saveChanges();
    return message;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:10,代码来源:SimpleEmailServiceJavaMailSenderTest.java

示例8: testEncodedFromToAddresses

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
public void testEncodedFromToAddresses() throws Exception
{
    // RFC1342
    String addressString = "[email protected]";
    String personalString = "�?р�?ений Ковальчук";
    InternetAddress address = new InternetAddress(addressString, personalString, "UTF-8");
    
    // Following method returns the address with quoted personal aka <["�?р�?ений Ковальчук"] <[email protected]>>
    // NOTE! This should be coincided with RFC822MetadataExtracter. Would 'addresses' be quoted or not? 
    // String decodedAddress = address.toUnicodeString();
    // So, just using decode, for now
    String decodedAddress = MimeUtility.decodeText(address.toString());
    
    // InternetAddress.toString(new Address[] {address}) - is used in the RFC822MetadataExtracter
    // So, compare with that
    assertFalse("Non ASCII characters in the address should be encoded", decodedAddress.equals(InternetAddress.toString(new Address[] {address})));
    
    MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
    
    MimeMessageHelper messageHelper = new MimeMessageHelper(message, false, "UTF-8");
    
    messageHelper.setText("This is a sample message for ALF-5647");
    messageHelper.setSubject("This is a sample message for ALF-5647");
    messageHelper.setFrom(address);
    messageHelper.addTo(address);
    messageHelper.addCc(address);
    
    // Creating the message node in the repository
    String name = AlfrescoImapConst.MESSAGE_PREFIX + GUID.generate();
    FileInfo messageFile = fileFolderService.create(testImapFolderNodeRef, name, ContentModel.TYPE_CONTENT);
    // Writing a content.
    new IncomingImapMessage(messageFile, serviceRegistry, message);
    
    // Getting the transformed properties from the repository
    // cm:originator, cm:addressee, cm:addressees, imap:messageFrom, imap:messageTo, imap:messageCc
    Map<QName, Serializable> properties = nodeService.getProperties(messageFile.getNodeRef());
    
    String cmOriginator = (String) properties.get(ContentModel.PROP_ORIGINATOR);
    String cmAddressee = (String) properties.get(ContentModel.PROP_ADDRESSEE);
    @SuppressWarnings("unchecked")
    List<String> cmAddressees = (List<String>) properties.get(ContentModel.PROP_ADDRESSEES);
    String imapMessageFrom = (String) properties.get(ImapModel.PROP_MESSAGE_FROM);
    String imapMessageTo = (String) properties.get(ImapModel.PROP_MESSAGE_TO);
    String imapMessageCc = (String) properties.get(ImapModel.PROP_MESSAGE_CC);
    
    assertNotNull(cmOriginator);
    assertEquals(decodedAddress, cmOriginator);
    assertNotNull(cmAddressee);
    assertEquals(decodedAddress, cmAddressee);
    assertNotNull(cmAddressees);
    assertEquals(1, cmAddressees.size());
    assertEquals(decodedAddress, cmAddressees.get(0));
    assertNotNull(imapMessageFrom);
    assertEquals(decodedAddress, imapMessageFrom);
    assertNotNull(imapMessageTo);
    assertEquals(decodedAddress, imapMessageTo);
    assertNotNull(imapMessageCc);
    assertEquals(decodedAddress, imapMessageCc);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:60,代码来源:ImapMessageTest.java

示例9: sendSupportMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
public void sendSupportMail(IssueForm form) {
	if (!isReportingEnabled()) {
		log.error("Cannot send support mail: no address is configured");
		return;
	}
	
	try {
		MimeMessage message = mailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(message, true);

		// Headers
		
		helper.setFrom(environment.getProperty("shiny.proxy.support.mail-from-address", "[email protected]"));
		helper.addTo(supportAddress);
		helper.setSubject("ShinyProxy Error Report");

		// Body
		
		StringBuilder body = new StringBuilder();
		String lineSep = System.getProperty("line.separator");
		body.append(String.format("This is an error report generated by ShinyProxy%s", lineSep));
		body.append(String.format("User: %s%s", form.userName, lineSep));
		if (form.appName != null) body.append(String.format("App: %s%s", form.appName, lineSep));
		if (form.currentLocation != null) body.append(String.format("Location: %s%s", form.currentLocation, lineSep));
		if (form.customMessage != null) body.append(String.format("Message: %s%s", form.customMessage, lineSep));
		helper.setText(body.toString());

		// Attachments
		
		if (isContainerLoggingEnabled()) {
			Proxy activeProxy = null;
			for (Proxy proxy: dockerService.listProxies()) {
				if (proxy.userName.equals(form.getUserName()) && proxy.appName.equals(form.getAppName())) {
					activeProxy = proxy;
					break;
				}
			}
			if (activeProxy != null) {
				Path[] filePaths = getLogFilePaths(activeProxy.containerId);
				for (Path p: filePaths) {
					if (Files.exists(p)) helper.addAttachment(p.toFile().getName(), p.toFile());
				}
			}
		}
		
		mailSender.send(message);
	} catch (Exception e) {
		throw new RuntimeException("Failed to send email", e);
	}
}
 
开发者ID:openanalytics,项目名称:shinyproxy,代码行数:51,代码来源:LogService.java


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