本文整理汇总了Java中org.springframework.mail.javamail.MimeMessageHelper.getMimeMessage方法的典型用法代码示例。如果您正苦于以下问题:Java MimeMessageHelper.getMimeMessage方法的具体用法?Java MimeMessageHelper.getMimeMessage怎么用?Java MimeMessageHelper.getMimeMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.mail.javamail.MimeMessageHelper
的用法示例。
在下文中一共展示了MimeMessageHelper.getMimeMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformAndSend
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
protected void transformAndSend(InputStream template, Map<String, Object> arguments, MimeMessageHelper helper)
throws MessagingException, IOException {
if (!enabled) {
log.warn("Mail message was silently consumed because mail system is disabled.");
return;
}
String text = templater.transform(template, arguments);
helper.setText(text, true);
MimeMessage message = helper.getMimeMessage();
if (message.getAllRecipients() != null && message.getAllRecipients().length > 0) {
sender.send(message);
} else {
log.warn("Mail message was silently consumed because there were no recipients.");
}
}
示例2: 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();
}
示例3: sendHtmlMail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
* 发送html邮件
*
* @throws MessagingException
* @throws AddressException
*/
public void sendHtmlMail(String from, String[] to, String title, String text)
throws AddressException, MessagingException {
long start = System.currentTimeMillis();
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "GBK");
InternetAddress[] toArray = new InternetAddress[to.length];
for (int i = 0; i < to.length; i++) {
toArray[i] = new InternetAddress(to[i]);
}
messageHelper.setFrom(new InternetAddress(from));
messageHelper.setTo(toArray);
messageHelper.setSubject(title);
messageHelper.setText(text, true);
mimeMessage = messageHelper.getMimeMessage();
mailSender.send(mimeMessage);
long end = System.currentTimeMillis();
LOG.info("send mail start:" + start + " end :" + end);
}
示例4: toMimeMessage
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private MimeMessage toMimeMessage(final Mail mail) throws MessagingException {
final MimeMessageHelper helper = new MimeMessageHelper(mailSender.createMimeMessage());
helper.setTo(mail.getTo());
helper.setFrom(mail.getFrom());
helper.setSubject(mail.getSubject());
helper.setText(mail.getText(), true);
return helper.getMimeMessage();
}
示例5: sendEmail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private void sendEmail(final Action ruleAction, MimeMessageHelper preparedMessage)
{
try
{
// Send the message unless we are in "testMode"
if (!testMode)
{
mailService.send(preparedMessage.getMimeMessage());
onSend();
}
else
{
lastTestMessage = preparedMessage.getMimeMessage();
testSentCount++;
}
}
catch (NullPointerException | MailException e)
{
onFail();
String to = (String)ruleAction.getParameterValue(PARAM_TO);
if (to == null)
{
Object obj = ruleAction.getParameterValue(PARAM_TO_MANY);
if (obj != null)
{
to = obj.toString();
}
}
// always log the failure
logger.error("Failed to send email to " + to + " : " + e);
// optionally ignore the throwing of the exception
Boolean ignoreError = (Boolean)ruleAction.getParameterValue(PARAM_IGNORE_SEND_FAILURE);
if (ignoreError == null || ignoreError.booleanValue() == false)
{
throw new AlfrescoRuntimeException("Failed to send email to:" + to);
}
}
}
示例6: sendEmail
import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private void sendEmail(final Action ruleAction, MimeMessageHelper preparedMessage)
{
try
{
// Send the message unless we are in "testMode"
if (!testMode)
{
mailService.send(preparedMessage.getMimeMessage());
onSend();
}
else
{
lastTestMessage = preparedMessage.getMimeMessage();
testSentCount++;
}
}
catch (MailException e)
{
onFail();
String to = (String)ruleAction.getParameterValue(PARAM_TO);
if (to == null)
{
Object obj = ruleAction.getParameterValue(PARAM_TO_MANY);
if (obj != null)
{
to = obj.toString();
}
}
// always log the failure
logger.error("Failed to send email to " + to + " : " + e);
// optionally ignore the throwing of the exception
Boolean ignoreError = (Boolean)ruleAction.getParameterValue(PARAM_IGNORE_SEND_FAILURE);
if (ignoreError == null || ignoreError.booleanValue() == false)
{
throw new AlfrescoRuntimeException("Failed to send email to:" + to);
}
}
}