本文整理汇总了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();
}
}
示例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);
}
示例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);
}
示例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());
}
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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());
}
示例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);
}
示例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());
}
}
}
示例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();
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
示例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);
}
}