當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。