本文整理汇总了Java中org.springframework.mail.javamail.MimeMessageHelper.setFrom方法的典型用法代码示例。如果您正苦于以下问题:Java MimeMessageHelper.setFrom方法的具体用法?Java MimeMessageHelper.setFrom怎么用?Java MimeMessageHelper.setFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.mail.javamail.MimeMessageHelper
的用法示例。
在下文中一共展示了MimeMessageHelper.setFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例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: 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);
}
}
示例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 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());
}
}
}
示例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(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());
}
}
}
示例7: 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);
}
示例8: prepareEmail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private int prepareEmail(MimeMessage mimeMessage, String subject, String emailAddresses) throws Exception {
int toCount = 0;
if (!CommonUtil.isEmptyString(emailAddresses)) {
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false, EMAIL_ENCODING);
mimeMessageHelper.setSubject(subject);
mimeMessageHelper.setText(output.toString());
mimeMessageHelper.setFrom(Settings.getEmailExecFromAddress(), Settings.getEmailExecFromName());
String[] addresses = emailAddressSeparatorRegexp.split(emailAddresses, -1);
for (int i = 0; i < addresses.length; i++) {
if (!CommonUtil.isEmptyString(addresses[i])) {
mimeMessageHelper.addTo(addresses[i].trim());
toCount++;
}
}
}
return toCount;
}
示例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.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);
}
}
示例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 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());
}
}
示例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());
}
}
示例12: sendHtmlEmail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
public int sendHtmlEmail(String subject, String content, String to) {
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "utf-8");
mimeMessage.setContent(content, "text/html;charset=utf-8");
messageHelper.setFrom(mailMessage.getFrom());
messageHelper.setSubject(subject); //主题
messageHelper.setTo(to); //发送给
messageHelper.setCc(mailMessage.getFrom()); //抄送
mailSender.send(mimeMessage); //发送邮件
} catch (Exception e) {
logger.error("the email send error ! content: {}, exception: {}", content, e);
return -1;
}finally {
}
return 1;
}
示例13: alert
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
public void alert(BaseRule rule, String content) throws Exception {
Config ruleConfig = rule.getConfig();
List<String> recipients = ruleConfig.getStringList("alerter.email.recipients");
String from = "";
String subject = "";
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper mailMessage = new MimeMessageHelper(mimeMessage, false, "utf-8");
mailMessage.setFrom(from);
mailMessage.setTo(recipients.toArray(new String[recipients.size()]));
mailMessage.setSubject(subject);
mimeMessage.setContent(content, "text/html");
}
示例14: sendEmail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Async
public void sendEmail(final String to, final String subject, final String content, final boolean isMultipart,
final boolean isHtml) {
final MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setFrom(uaaProperties.getMail().getFrom());
message.setTo(to);
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
LOGGER.debug("Sent email to User '{}' with subject '{}'", to, subject);
} catch (final MessagingException | MailException e) {
LOGGER.warn("Mail could not be sent to user '{}'", to, e);
}
}
示例15: sendEmail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
protected void sendEmail(String email, String authCode) throws MessagingException, UnsupportedEncodingException {
MimeMessage mimeMessage = mMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, "UTF-8");
helper.setSubject("欢迎加入 LsPush 大家庭");
helper.setFrom(serverEmail, serverName);
helper.setTo(email);
String authLink = String.format("%s/user/auth?auth_code=%s", serverUrl, authCode);
final Context ctx = new Context(Locale.CHINA);
ctx.setVariable("serverUrl", serverUrl);
ctx.setVariable("serverName", serverName);
ctx.setVariable("email", email);
ctx.setVariable("authCode", authCode);
ctx.setVariable("authLink", authLink);
String html = mTemplateEngine.process("lspush_captcha_email", ctx);
helper.setText(html, true);
mMailSender.send(mimeMessage);
}