本文整理汇总了Java中org.springframework.mail.MailSender.send方法的典型用法代码示例。如果您正苦于以下问题:Java MailSender.send方法的具体用法?Java MailSender.send怎么用?Java MailSender.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.mail.MailSender
的用法示例。
在下文中一共展示了MailSender.send方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMailToAuthor
import org.springframework.mail.MailSender; //导入方法依赖的package包/类
private Consumer<StreamItemEntity> sendMailToAuthor(MailSender mailSender,
String markerAuthor,
String itemId,
String markerType) {
return foundItem -> {
Optional<String> authorMail = ofNullable(foundItem.getAuthor().getEmail());
if (validMailAddress(authorMail) &&
!itemAuthorEqualsMarkerAuthor(markerAuthor, foundItem)) {
SimpleMailMessage mentionMessage = new SimpleMailMessage();
mentionMessage.setFrom("[email protected]");
mentionMessage.setSubject("You got a new '" + markerType + "' on a put!");
mentionMessage.setTo(foundItem.getAuthor().getEmail());
mentionMessage.setText(new MailTemplates()
.create("markerNotification")
.replace("markerType", markerType)
.replace("markerAuthor", "@" + markerAuthor)
.replace("link", "https://putput.org/#/item/" + itemId)
.replace("content", contentPreview(foundItem))
.getText()
);
mailSender.send(mentionMessage);
}
};
}
示例2: execute
import org.springframework.mail.MailSender; //导入方法依赖的package包/类
@Override
public void execute(ExecutionContext executionContext) {
MailSender mailSender = executionContext.service(MailSender.class);
String confirmationCode = UUID.randomUUID().toString();
executionContext.setProperty(ForgotPasswordFlow.confirmationCode, confirmationCode);
SimpleMailMessage confirmationMail = new SimpleMailMessage();
confirmationMail.setFrom("[email protected]");
confirmationMail.setSubject("Your Password Reset Request");
confirmationMail.setTo(executionContext.property(ForgotPasswordFlow.emailAddress));
confirmationMail.setText(new MailTemplates()
.create("passwordRequest")
.replace("code", confirmationCode)
.getText()
);
mailSender.send(confirmationMail);
log.info("sent confirmation");
}
示例3: main
import org.springframework.mail.MailSender; //导入方法依赖的package包/类
public static void main(String[] args) {
MailServerSettingsImpl mailServerSettings = new MailServerSettingsImpl();
mailServerSettings.setMailServer("mail.gmx.net");
mailServerSettings.setMailServerPort(587);
mailServerSettings.setFrom("[email protected]");
mailServerSettings.setUseAuth(true);
mailServerSettings.setUseTls(true);
mailServerSettings.setUsername("[email protected]");
mailServerSettings.setPassword("bereitsverwendet");
// mailServerSettings.setMailServer("smtp.gmail.com");
// mailServerSettings.setMailServerPort(25);
// mailServerSettings.setFrom("[email protected]");
// mailServerSettings.setUseAuth(true);
// mailServerSettings.setUseTls(true);
// mailServerSettings.setUsername("[email protected]");
// mailServerSettings.setPassword("Eclipse1");
MailSender customMailSender = createCustomMailSender(mailServerSettings);
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setSubject("My Tst Subj");
mailMessage.setTo("[email protected]");
mailMessage.setText("My TEst Msg");
mailMessage.setFrom(mailServerSettings.getFrom());
if (StringUtils.isNotEmpty(mailServerSettings.getReplyTo())) {
mailMessage.setReplyTo(mailServerSettings.getReplyTo());
}
customMailSender.send(mailMessage);
}
示例4: sendMessageToParticipant
import org.springframework.mail.MailSender; //导入方法依赖的package包/类
protected void sendMessageToParticipant(final Participant participant, final String subject, final String messageText,
final MailSender mailSender, final Optional<MailServerSettings> customMailServerSettings,
final Map<String, Boolean> sendingResults, final Locale locale) {
final String teamMemberEmail = participant.getEmail();
if (!isEmailValid(teamMemberEmail)) {
putInvalidMailToResults(sendingResults, participant, teamMemberEmail, locale);
return;
}
final String email = getMailAddress(teamMemberEmail);
SimpleMailMessage mailMessage = createSimpleMailMessage(customMailServerSettings);
mailMessage.setSubject(subject);
mailMessage.setTo(email);
mailMessage.setText(messageText);
LOGGER.info("Send mail with size of {} characters to {}", messageText.length(), email);
try {
mailSender.send(mailMessage);
sendingResults.put(email, true);
}
catch (Exception ex) {
sendingResults.put(email, false);
LOGGER.error("Failed to send mail to {}", email, ex);
}
}
示例5: checkEmailConnection
import org.springframework.mail.MailSender; //导入方法依赖的package包/类
/**
* Tries to send a tets email to the passed testEmailAddress with using the passed subject and message.<br>
* If sending succeeds then no exception will be thrown.
*
* @param mailServerSettings The settings of the mail server on which it shall be tried to send the test mail
* @param testEmailAddress
* @param testSubject
* @param testMessage
* @throws MailServerConnectionFailedException Thrown when test email could not be sent
*/
public void checkEmailConnection(MailServerSettings mailServerSettings, String testEmailAddress, String testSubject, String testMessage)
throws MailServerConnectionFailedException {
MailSender customMailSender = createCustomMailSender(mailServerSettings);
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setSubject(testSubject);
mailMessage.setTo(testEmailAddress);
mailMessage.setText(testMessage);
mailMessage.setFrom(mailServerSettings.getFrom());
if (StringUtils.isNotEmpty(mailServerSettings.getReplyTo())) {
mailMessage.setReplyTo(mailServerSettings.getReplyTo());
}
try {
customMailSender.send(mailMessage);
}
catch (MailAuthenticationException authEx) {
throw new MailServerConnectionFailedException(authEx).setMailConnectionError(MAIL_CONNECTION_ERROR.AUTHENTICATION);
}
catch (MailSendException sendEx) {
throw new MailServerConnectionFailedException(sendEx).setMailConnectionError(MAIL_CONNECTION_ERROR.SEND);
}
catch (Exception ex) {
throw new MailServerConnectionFailedException(ex).setMailConnectionError(MAIL_CONNECTION_ERROR.UNKNOWN);
}
}