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


Java MimeMessageHelper类代码示例

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


MimeMessageHelper类属于org.springframework.mail.javamail包,在下文中一共展示了MimeMessageHelper类的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: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //导入依赖的package包/类
@Override
public void sendEmail(final UserDTO user, String url) {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setTo(user.getEmail());
            message.setSubject(SUBJECT);
            message.setFrom(EMAIL_FROM); // could be parameterized...
            Map model = new HashMap();
            model.put("user", user);
            model.put("url", url);
            String text = VelocityEngineUtils.mergeTemplateIntoString(
                    velocityEngine, "org/enricogiurin/sushibar/registration-confirmation.vm", model);
            message.setText(text, true);
        }
    };
    this.emailSender.send(preparator);
}
 
开发者ID:egch,项目名称:sushi-bar-BE,代码行数:19,代码来源:EmailSenderImpl.java

示例3: sendWithAttachment

import org.springframework.mail.javamail.MimeMessageHelper; //导入依赖的package包/类
@Override
public void sendWithAttachment(String to, String subject, String templateName, Map<String, String> data,
    InputStream attachment, String attachmentName) {

    LOG.debug("Sending email from {} to {} with subject {}", from, to, subject);

    MimeMessagePreparator messagePreparator = message -> {
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setTo(to);
        helper.setFrom(from);
        helper.setSubject(subject);
        helper.setText(templateService.createTemplate(templateName, data));
        helper.addAttachment(attachmentName, new ByteArrayResource(IOUtils.toByteArray(attachment)));
    };
    mailSender.send(messagePreparator);

    IOUtils.closeQuietly(attachment);
}
 
开发者ID:Contargo,项目名称:iris,代码行数:19,代码来源:SpringEmailService.java

示例4: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //导入依赖的package包/类
void sendEmail(String to, String subject, String content, String from) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        false, true, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(from);
        message.setSubject(subject);
        message.setText(content, true);
        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:xm-online,项目名称:xm-uaa,代码行数:23,代码来源:MailService.java

示例5: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //导入依赖的package包/类
@Override
public void sendEmail(@NonNull final Mail _mail,
                      @NonNull final String _body,
                      @Nullable final String _attachmentFilename,
                      @Nullable final byte[] _pdfAttachment) {
    try {
        // Prepare message using a Spring helper
        final MimeMessage mimeMessage = mailSender.createMimeMessage();
        final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, (_pdfAttachment != null), StandardCharsets.UTF_8.name());
        message.setSubject("Tifoon Scan Report");
        message.setFrom(_mail.getSender());
        message.setTo(_mail.getRecipient());

        message.setText(_body, true);

        if (_attachmentFilename != null && _pdfAttachment != null) {
            message.addAttachment(_attachmentFilename, new ByteArrayResource(_pdfAttachment));
        }

        // Send mail
        mailSender.send(mimeMessage);
    } catch (MessagingException _e) {
        log.error("Failed to send e-mail", _e);
    }
}
 
开发者ID:jonfryd,项目名称:tifoon,代码行数:26,代码来源:ReportEmailSenderServiceImpl.java

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

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

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

示例9: sendMailWithTemplate

import org.springframework.mail.javamail.MimeMessageHelper; //导入依赖的package包/类
@Override
public void sendMailWithTemplate(final TemplateMailTO mailParameters) throws MailException {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);

            message.setTo(mailParameters.getToMailAddress());
            message.setFrom(mailParameters.getFromMailAddress());
            message.setSubject(mailParameters.getSubject());
            if (mailParameters.hasCcMailAddress()) {
                message.setCc(mailParameters.getCcMailAddress());
            }
            if (mailParameters.hasReplyTo()) {
                message.setReplyTo(mailParameters.getReplyTo());
            }
            String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, mailParameters.getTemplateLocation(), mailParameters.getTemplateProperties());
            log.debug("*** TEST text='" + text + "'");
            message.setText(text, true);
            message.setValidateAddresses(true);

        }
    };
    this.mailSender.send(preparator);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:26,代码来源:MailServiceImpl.java

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

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

示例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 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:GastonMauroDiaz,项目名称:buenojo,代码行数:20,代码来源:MailService.java

示例13: sendMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入依赖的package包/类
private void sendMail(Optional<MimeMessageHelper> oMessage, MailType emailType) throws EmailNotSentException {
    String recipient = null;
    try {
        if (oMessage.isPresent()) {
            // TODO: don't assume that the "to" email field has at least one address
            recipient = oMessage.get().getMimeMessage().getRecipients(Message.RecipientType.TO)[0].toString();
            if (!this.enabled) {
                LOG.info("Skipping sending email type {} to {} with body: {}",
                        emailType, recipient, oMessage.get().getMimeMessage().getContent());
                return;
            }
            LOG.info("Sending email type {} to {}", emailType, recipient);
            this.javaMailService.send(oMessage.get().getMimeMessage());
        } else {
            throw new Exception();
        }
    } catch (Exception e) {
        LOG.error("CRITICAL: error sending email type {} to {}. Reason {}", emailType, recipient, e.toString());
        throw new EmailNotSentException(e);
    }
}
 
开发者ID:modum-io,项目名称:tokenapp-backend,代码行数:22,代码来源:MailService.java

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

示例15: 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:ElectronicArmory,项目名称:Armory,代码行数:20,代码来源:MailService.java


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