本文整理汇总了Java中org.springframework.mail.javamail.MimeMessageHelper.setSubject方法的典型用法代码示例。如果您正苦于以下问题:Java MimeMessageHelper.setSubject方法的具体用法?Java MimeMessageHelper.setSubject怎么用?Java MimeMessageHelper.setSubject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.mail.javamail.MimeMessageHelper
的用法示例。
在下文中一共展示了MimeMessageHelper.setSubject方法的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包/类
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());
}
}
}
示例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(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);
}
}
示例4: 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);
}
示例5: 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);
}
}
示例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 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);
}
}
示例7: 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());
}
}
}
示例8: 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();
}
示例9: 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);
}
}
示例10: 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());
}
示例11: sendEmail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
* To send email.
*
* @param mailParam its map containing mail headers details. i.e. "from"
*/
public void sendEmail(EmailDTO emailDTO) {
try {
if (Objects.nonNull(emailDTO)) {
MimeMessage mail = javaMailSenderImpl.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mail, true);
helper.setSubject(emailDTO.getSubject());
helper.setText(emailDTO.getMessage(), true);
helper.setFrom(emailDTO.getFrom(), configurationService.getMailConfiguration().getFrom());
helper.setTo(emailDTO.getTo());
if (Objects.nonNull(emailDTO.getAttachment())) {
helper.addAttachment(emailDTO.getAttachmentName(), emailDTO.getAttachment());
}
javaMailSenderImpl.send(mail);
}
} catch (MessagingException | MailException | UnsupportedEncodingException e) {
logger.error("Exception while sending mail notification.", 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 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: sendAttachmentsMail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
* 发送带附件的邮件
*/
@Test
public void sendAttachmentsMail() {
MimeMessage message = null;
try {
message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(Sender);
helper.setTo(Sender);
helper.setSubject("主题:带附件的邮件");
helper.setText("带附件的邮件内容");
//注意项目路径问题,自动补用项目路径
FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/picture.jpg"));
//加入邮件
helper.addAttachment("图片.jpg", file);
} catch (Exception e) {
e.printStackTrace();
}
mailSender.send(message);
}
示例14: sendInlineMail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
* 发送带静态资源的邮件
*/
@Test
public void sendInlineMail() {
MimeMessage message = null;
try {
message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(Sender);
helper.setTo(Sender);
helper.setSubject("主题:带静态资源的邮件");
//第二个参数指定发送的是HTML格式,同时cid:是固定的写法
helper.setText("<html><body>带静态资源的邮件内容 图片:<img src='cid:picture' /></body></html>", true);
FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/picture.jpg"));
helper.addInline("picture", file);
} catch (Exception e) {
e.printStackTrace();
}
mailSender.send(message);
}
示例15: sendAttachmentsMail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Test
public void sendAttachmentsMail() throws Exception {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom("[email protected]");
helper.setTo("[email protected]");
helper.setSubject("主题:有附件");
helper.setText("有附件的邮件");
FileSystemResource file = new FileSystemResource(new File("weixin.jpg"));
helper.addAttachment("附件-1.jpg", file);
helper.addAttachment("附件-2.jpg", file);
mailSender.send(mimeMessage);
}