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


Java MimeMessageHelper.setText方法代码示例

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


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

示例1: sendMailWithUsername

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

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

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

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:28,代码来源:MailServiceImpl.java

示例2: send

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
 * Sends e-mail using Velocity template for the body and the properties
 * passed in as Velocity variables.
 *
 * @param msg The e-mail message to be sent, except for the body.
 * @param hTemplateVariables Variables to use when processing the template.
 */
protected void send(SimpleMailMessage msg, String language, String template, Map<String, Object> hTemplateVariables) {

    LOG.info("Send email ...");
    MimeMessagePreparator preparator = (MimeMessage mimeMessage) -> {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
        message.setTo(msg.getTo());
        message.setFrom(msg.getFrom());
        message.setSubject(msg.getSubject());

        String body = VelocityEngineUtils.mergeTemplateIntoString(
                velocityEngine, 
                "/" + template + "." + language + ".vm", 
                "UTF-8", 
                hTemplateVariables);

        LOG.log(Level.INFO, "Body: {0}", body);

        message.setText(body, true);
    };

    mailSender.send(preparator);

    LOG.log(Level.INFO, "Sender {0}", msg.getFrom());
    LOG.log(Level.INFO, "Recipient {0}", msg.getTo());
}
 
开发者ID:lordoftheflies,项目名称:wonderjameeee,代码行数:33,代码来源:VelocityEmailSender.java

示例3: 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-Personal,代码行数:21,代码来源:MailUtil.java

示例4: 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:IBM,项目名称:Microservices-with-JHipster-and-Spring-Boot,代码行数:20,代码来源:MailService.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:quanticc,项目名称:sentry,代码行数:20,代码来源:MailService.java

示例6: createActivationMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
 * creates a activation mail.
 * 
 * may throw a RuntimeException if no MimeMessage can be created
 * 
 * @param activation {@link PendingAccountActivation}  has to contain an id and an UisUser. UisUser should contain an mail address. 
 * @return {@link MimeMessage}
 */
private MimeMessage createActivationMail(PendingAccountActivation activation) throws RuntimeException{
	log.info("creating activation mail for pending activation");
    MimeMessage mimeMsg = mailSender.createMimeMessage();
    MimeMessageHelper msg = new MimeMessageHelper(mimeMsg, "UTF-8");

    try {
        msg.setTo(activation.getForUser().getEmail());
        msg.setSubject(messages.get(MAIL_SUBJECT));
        msg.setText(messageContent(activation), true);
    } catch (MessagingException e) {
    	log.warn("activation message creation FAILED! throwing runtime-exception now");
        throw new RuntimeException(e);
    }

    return msg.getMimeMessage();
}
 
开发者ID:university-information-system,项目名称:uis,代码行数:25,代码来源:UserCreationServiceImpl.java

示例7: 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

示例8: 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:kalnee,项目名称:trivor,代码行数:24,代码来源:MailService.java

示例9: sendMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private void sendMail(SendMailActionMsg msg) throws MessagingException {
    log.debug("Sending mail {}", msg);
    MimeMessage mailMsg = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(mailMsg, "UTF-8");
    helper.setFrom(msg.getFrom());
    helper.setTo(msg.getTo());
    if (!StringUtils.isEmpty(msg.getCc())) {
        helper.setCc(msg.getCc());
    }
    if (!StringUtils.isEmpty(msg.getBcc())) {
        helper.setBcc(msg.getBcc());
    }
    helper.setSubject(msg.getSubject());
    helper.setText(msg.getBody());
    mailSender.send(helper.getMimeMessage());
    log.debug("Mail sent {}", msg);
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:18,代码来源:MailPlugin.java

示例10: sendTemplateMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
     * 发送模板邮件
     * 在Spring Boot中也能使用模板引擎来实现模板化的邮件发送。
     * 关于模板邮件,SpringBoot 原本是支持 velocity,
     * 在 1.4 版本后又抛弃了 velocity,暂时只支持 freemaker。
     *
     * <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-freemarker</artifactId>
     </dependency>
     */
    @Test
    public void sendTemplateMail() {
        MimeMessage message = null;
        try {
            message = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message, true);
            helper.setFrom(Sender);
            helper.setTo(Sender);
            helper.setSubject("主题:模板邮件");

            Map<String, Object> model = new HashMap();
            model.put("username", "测试名");

            //修改 application.properties 文件中的读取路径
//            FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
//            configurer.setTemplateLoaderPath("classpath:templates");
            //读取 html 模板
            Template template = freeMarkerConfigurer.getConfiguration().getTemplate("template.ftl");
            String html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
            helper.setText(html, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        mailSender.send(message);
    }
 
开发者ID:zhaoshuxue,项目名称:springBoot,代码行数:37,代码来源:UnitTest.java

示例11: 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 '{}', exception is: {}", to, e.getMessage());
    }
}
 
开发者ID:flanciskinho,项目名称:prove.jwt,代码行数:20,代码来源:MailService.java

示例12: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Async
@Override
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(tquestoProperties.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:anitechcs,项目名称:tquesto,代码行数:21,代码来源:MailServiceImpl.java

示例13: sendText

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
public void sendText(String address, String subject, String content, boolean html) {
    init();
    MimeMessage msg = sender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(msg, true, "UTF-8");
        message.setFrom(sender.getUsername());
        message.setSubject(subject);
        message.setTo(address);
        message.setText(content, html);

        new Thread(() -> {
            sender.send(msg);
        }).start();

    } catch (Exception e) {
        logger.warn(e.getMessage());
    }
}
 
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:20,代码来源:EmailSenderImpl.java

示例14: 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:benoyprakash,项目名称:java-hostel,代码行数:21,代码来源:MailService.java

示例15: notify

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
public void notify(SwingValidateContext context, String ... others) {
    final Context ctx = new Context(Locale.SIMPLIFIED_CHINESE);
    ctx.setVariable("context", context);
    ctx.setVariable("pushTime", new Date());
    final String htmlContent = this.templateEngine.process("mail/"+others[0], ctx);
    final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
    final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
    try {
        message.setFrom(EMAIL_FROM);
        message.setTo(others[1]);
        message.setSubject(others[2]);
        message.setText(htmlContent, true);
        this.mailSender.send(mimeMessage);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
开发者ID:Justice-love,项目名称:stockAnalysis,代码行数:20,代码来源:EmailNotifyService.java


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