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