当前位置: 首页>>代码示例>>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;未经允许,请勿转载。