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


Java MimeMessageHelper.setTo方法代碼示例

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


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

示例1: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        log.warn("Email could not be sent to user '{}'", to, e);
    }
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:20,代碼來源:MailService.java

示例2: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
開發者ID:oktadeveloper,項目名稱:jhipster-microservices-example,代碼行數:24,代碼來源:MailService.java

示例3: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(mailFromDisplay);
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
開發者ID:megadotnet,項目名稱:SpringBootDemoApp,代碼行數:23,代碼來源:MailService.java

示例4: sendMailWithNewPassword

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithNewPassword(
        @NotBlank @Email final String email,
        @NotBlank final String newPassword
) {
    log.info("Called with e-mail {}, newPassword {}", email, newPassword);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

        helper.setTo(email);
        helper.setSubject("Recover password");
        helper.setText("Your new password: " + "<b>" + newPassword + "</b>", true);

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:28,代碼來源:MailServiceImpl.java

示例5: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent e-mail to User '{}'", to);
    } catch (Exception e) {
        log.warn("E-mail could not be sent to user '{}'", to, e);
    }
}
 
開發者ID:AppertaFoundation,項目名稱:Code4Health-Platform,代碼行數:20,代碼來源:MailService.java

示例6: createHtmlEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
private static void createHtmlEmail(int i){
    try {
        JavaMailSender sender = getEmailSender();

        MimeMessage message = sender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setTo("[email protected]");
        helper.setFrom("[email protected]");
        helper.setSubject("Test-Mail " + i);
        helper.setText("<html><head></head><body>This is the test mail number " + i + "</body>", true);

        sender.send(message);
    } catch (MessagingException e){
        throw new RuntimeException("Failed to create mail", e);
    }
}
 
開發者ID:gessnerfl,項目名稱:fake-smtp-server,代碼行數:17,代碼來源:TestDataCreator.java

示例7: send

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Override
public void send(NotificationType type, Recipient recipient, String attachment) throws MessagingException, IOException {

	final String subject = env.getProperty(type.getSubject());
	final String text = MessageFormat.format(env.getProperty(type.getText()), recipient.getAccountName());

	MimeMessage message = mailSender.createMimeMessage();

	MimeMessageHelper helper = new MimeMessageHelper(message, true);
	helper.setTo(recipient.getEmail());
	helper.setSubject(subject);
	helper.setText(text);

	if (StringUtils.hasLength(attachment)) {
		helper.addAttachment(env.getProperty(type.getAttachment()), new ByteArrayResource(attachment.getBytes()));
	}

	mailSender.send(message);

	log.info("{} email notification has been send to {}", type, recipient.getEmail());
}
 
開發者ID:sniperqpc,項目名稱:Spring-cloud-gather,代碼行數:22,代碼來源:EmailServiceImpl.java

示例8: prepareMessage

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
private Optional<MimeMessageHelper> prepareMessage(Optional<MimeMessage> oMimeMessage,
                                                   String recipient, String subject, MailType emailType)
        throws EmailNotPreparedException {
    Optional<MimeMessageHelper> oMessage = Optional.empty();
    try {
        if (oMimeMessage.isPresent()) {
            oMessage = Optional.ofNullable(new MimeMessageHelper(oMimeMessage.get(), true, "UTF-8"));
            if (oMessage.isPresent()) {
                MimeMessageHelper message = oMessage.get();
                message.setSubject(subject);
                message.setFrom(this.sendfrom);
                message.setTo(recipient);
                if ((this.enableBccToConfirmationEmail && emailType.equals(MailType.CONFIRMATION_EMAIL))
                        || (this.enableBccToSummaryEmail && emailType.equals(MailType.SUMMARY_EMAIL))) {
                    message.setBcc(this.admin);
                }
            }
        }
    } catch (MessagingException e) {
        LOG.error("Error building the message of email type {} to {}", emailType, recipient);
        throw new EmailNotPreparedException(e);
    }
    return oMessage;
}
 
開發者ID:modum-io,項目名稱:tokenapp-backend,代碼行數:25,代碼來源:MailService.java

示例9: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMailgun().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent e-mail to User '{}'", to);
    } catch (Exception e) {
        log.warn("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage());
    }
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:20,代碼來源:MailService.java

示例10: run

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Override
public void run() 
{
	if (null != mailMessage)
	{
		MimeMessage mimeMsg = mailSender.createMimeMessage();
		try
		{
			// 設置true,表示支持附件
			MimeMessageHelper msgHelper = new MimeMessageHelper(mimeMsg, true, "UTF-8");
			msgHelper.setFrom(mailMessage.getFromUser(), mailMessage.getCompanyName());
			msgHelper.setSubject(mailMessage.getSubject());
			String[] toArray = new String[mailMessage.getReceiveUsers().size()];
			msgHelper.setTo(mailMessage.getReceiveUsers().toArray(toArray));
			msgHelper.setText(mailMessage.getContent(), true);
			mailSender.send(mimeMsg);
		}
		catch (Exception e)
		{
			LOGGER.error("Send mail failed. Error message : {}", e.getMessage());
		}
	}
}
 
開發者ID:marlonwang,項目名稱:raven,代碼行數:24,代碼來源:MailSender.java

示例11: sendHtmlMail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
/**
 * 發送html郵件
 */
@Async("mailAsync")
public void sendHtmlMail(String to, String subject, String content) {
	MimeMessage message = mailSender.createMimeMessage();
	try {
		//true表示需要創建一個multipart message
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		helper.setText(content, true);
		helper.setSentDate(new Date());
		mailSender.send(message);
		logger.info("html郵件發送成功");
	} catch (MessagingException e) {
		logger.error("發送html郵件時發生異常!", e);
	}
}
 
開發者ID:CharleyXu,項目名稱:tulingchat,代碼行數:21,代碼來源:MailUtil.java

示例12: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
	log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
		isMultipart, isHtml, to, subject, content);

	// Prepare message using a Spring helper
	MimeMessage mimeMessage = javaMailSender.createMimeMessage();
	try {
		MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
		message.setTo(to);
		message.setFrom(jHipsterProperties.getMail().getFrom());
		message.setSubject(subject);
		message.setText(content, isHtml);
		javaMailSender.send(mimeMessage);
		log.debug("Sent email to User '{}'", to);
	} catch (Exception e) {
		if (log.isDebugEnabled()) {
			log.warn("Email could not be sent to user '{}'", to, e);
		} else {
			log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
		}
	}
}
 
開發者ID:alikemalocalan,項目名稱:MicroBlog,代碼行數:24,代碼來源:MailService.java

示例13: sendHtmlMail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
/**
 * 發送Html郵件
 */
@Test
public void sendHtmlMail() {
    MimeMessage message = null;
    try {
        message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(Sender);
        helper.setTo(Sender);
        helper.setSubject("標題:發送Html內容");

        StringBuffer sb = new StringBuffer();
        sb.append("<h1>大標題-h1</h1>")
                .append("<p style='color:#F00'>紅色字</p>")
                .append("<p style='text-align:right'>右對齊</p>");
        helper.setText(sb.toString(), true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    mailSender.send(message);
}
 
開發者ID:zhaoshuxue,項目名稱:springBoot,代碼行數:24,代碼來源:UnitTest.java

示例14: sendBugReport

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
public void sendBugReport(BugReport report) throws MailException, MessagingException {
    MimeMessage message = this.mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setTo(bugReportEmail);
    helper.setFrom(from);
    helper.setSubject(report.getSubject());
    helper.setText(report.getDescription());
    if (report.getAttachments() != null) {
        for (BugReportAttachment attachment : report.getAttachments()) {
            // Decode base64 encoded data
            byte[] data =  Base64.getDecoder().decode(attachment.getData());
            ByteArrayDataSource dataSource = new ByteArrayDataSource(data, attachment.getMimetype());
            helper.addAttachment(attachment.getName(), dataSource);
        }
    }
    this.mailSender.send(message);
}
 
開發者ID:MaritimeConnectivityPlatform,項目名稱:IdentityRegistry,代碼行數:18,代碼來源:EmailUtil.java

示例15: sendPasswordResetMail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendPasswordResetMail(String target,String reseturl,JavaMailSender javaMailSender) throws InterruptedException  {
	try {
		MimeMessage mimeMsg = javaMailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8");
		String content = (String) PropertyPlaceholder.getProperty("mail.template");
		content = content.replace("{reseturl}", reseturl);
		helper.setText(content, true);
		helper.setTo(new String[]{target});
		String title = (String) PropertyPlaceholder.getProperty("mail.title");
		helper.setSubject(title); 
		String authormail = (String) PropertyPlaceholder.getProperty("mail.sendfrom");
		String authorname = (String) PropertyPlaceholder.getProperty("mail.sendname");
		helper.setFrom(authormail,authorname);
		javaMailSender.send(mimeMsg);
		log.info("Password Reset Mail has been send to "+target);
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:zjlywjh001,項目名稱:PhrackCTF-Platform-Team,代碼行數:21,代碼來源:MailUtil.java


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