本文整理匯總了Java中org.springframework.mail.MailSender類的典型用法代碼示例。如果您正苦於以下問題:Java MailSender類的具體用法?Java MailSender怎麽用?Java MailSender使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MailSender類屬於org.springframework.mail包,在下文中一共展示了MailSender類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: processMention
import org.springframework.mail.MailSender; //導入依賴的package包/類
private void processMention(StreamItemContentParser.Mention mention, StreamItemEntity item, ExecutionContext taskContext) {
MailSender mailSender = taskContext.service(MailSender.class);
UserRepository userRepository = taskContext.service(UserRepository.class);
StreamItemRepository streamItemRepository = taskContext.service(StreamItemRepository.class);
Optional.ofNullable(userRepository.findByUsername(mention.getUsername())).ifPresent(foundUser -> {
if (ofNullable(foundUser.getEmail()).isPresent()) {
SimpleMailMessage mentionMessage = new SimpleMailMessage();
mentionMessage.setFrom("[email protected]");
mentionMessage.setSubject("You have been mentioned by @" + item.getAuthor().getUsername());
mentionMessage.setTo(foundUser.getEmail());
mentionMessage.setText(new MailTemplates()
.create("mention")
.data("item", item)
.data("referencedItem", ofNullable(item.getItemRef()).map(streamItemRepository::findOne).orElse(null))
.getText()
);
mailSender.send(mentionMessage);
}
});
}
示例3: 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");
}
示例4: shouldSendMailWithNewPassword
import org.springframework.mail.MailSender; //導入依賴的package包/類
@Test
public void shouldSendMailWithNewPassword() {
// given:
String userMailAddress = "[email protected]";
String newPassword = "newPassword";
PasswordEncoder passwordEncoder = mock(PasswordEncoder.class);
UserRepository userRepository = mock(UserRepository.class);
MailSender mailSender = mock(MailSender.class);
PasswordService passwordService = createPasswordService(newPassword, passwordEncoder, userRepository, mailSender);
// when:
when(passwordEncoder.encode(anyString())).thenReturn(newPassword);
when(userRepository.findByEmail(userMailAddress)).thenReturn(Optional.of(new UserEntity()));
Optional<PasswordService.PasswordResetSuccess> passwordReset = passwordService.resetPassword(userMailAddress);
// then:
assertThat(passwordReset.isPresent());
verify(mailSender).send(argThat(messageContaining(newPassword)));
}
示例5: sendDinnerRouteMessages
import org.springframework.mail.MailSender; //導入依賴的package包/類
public Map<String, Boolean> sendDinnerRouteMessages(List<Team> teams, DinnerRouteMessageFormatter formatter,
final Optional<MailServerSettings> customMailServerSettings) {
final Map<String, Boolean> sendingResults = new HashMap<String, Boolean>();
final MailSender mailSenderActive = getActiveMailSender(customMailServerSettings);
final String subject = formatter.getSubject();
for (Team team : teams) {
LOGGER.debug("Process team {} for dinnerroute message", team);
List<Team> teamDinnerRoute = TeamRouteBuilder.generateDinnerRoute(team);
for (Participant teamMember : team.getTeamMembers()) {
final String messageText = formatter.formatDinnerRouteMessage(teamMember, team, teamDinnerRoute);
sendMessageToParticipant(teamMember, subject, messageText, mailSenderActive, customMailServerSettings, sendingResults,
formatter.getLocale());
}
}
return sendingResults;
}
示例6: createCustomMailSender
import org.springframework.mail.MailSender; //導入依賴的package包/類
private MailSender createCustomMailSender(final MailServerSettings mailServerSettings) {
JavaMailSenderImpl result = new JavaMailSenderImpl();
result.setHost(mailServerSettings.getMailServer());
if (mailServerSettings.hasMailServerPort()) {
result.setPort(mailServerSettings.getMailServerPort());
}
if (mailServerSettings.isUseAuth()) {
result.setUsername(mailServerSettings.getUsername());
result.setPassword(mailServerSettings.getPassword());
result.getJavaMailProperties().put("mail.smtp.auth", "true");
}
else {
result.getJavaMailProperties().put("mail.smtp.auth", "false");
}
boolean useTls = mailServerSettings.isUseTls();
result.getJavaMailProperties().put("mail.smtp.starttls.enable", String.valueOf(useTls));
result.setDefaultEncoding("UTF-8");
return result;
}
示例7: GavinJobFactory
import org.springframework.mail.MailSender; //導入依賴的package包/類
public GavinJobFactory(DataService dataService, PlatformTransactionManager transactionManager,
UserDetailsService userDetailsService, JobExecutionUpdater jobExecutionUpdater, MailSender mailSender,
FileStore fileStore, RepositoryAnnotator cadd, RepositoryAnnotator exac, RepositoryAnnotator snpEff,
EffectBasedAnnotator gavin, MenuReaderService menuReaderService, Parser parser,
AnnotatorRunner annotatorRunner)
{
this.dataService = requireNonNull(dataService);
this.transactionManager = requireNonNull(transactionManager);
this.userDetailsService = requireNonNull(userDetailsService);
this.jobExecutionUpdater = requireNonNull(jobExecutionUpdater);
this.mailSender = requireNonNull(mailSender);
this.fileStore = requireNonNull(fileStore);
this.cadd = requireNonNull(cadd);
this.exac = requireNonNull(exac);
this.snpEff = requireNonNull(snpEff);
this.gavin = requireNonNull(gavin);
this.menuReaderService = requireNonNull(menuReaderService);
this.parser = requireNonNull(parser);
this.annotatorRunner = requireNonNull(annotatorRunner);
}
示例8: mailBean
import org.springframework.mail.MailSender; //導入依賴的package包/類
@Bean(autowire = Autowire.BY_TYPE)
public MailSender mailBean()
{
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(mailHost);
mailSender.setUsername(mailUserName);
mailSender.setPassword(mailPassword);
setUpMailPro(mailSender);
return mailSender;
}
示例9: mailSender
import org.springframework.mail.MailSender; //導入依賴的package包/類
@Bean
MailSender mailSender() {
return new MailSender() {
@Override
public void send(SimpleMailMessage simpleMessage) throws MailException {
// do nothing
}
@Override
public void send(SimpleMailMessage... simpleMessages) throws MailException {
// do nothing
}
};
}
示例10: AppointmentMailer
import org.springframework.mail.MailSender; //導入依賴的package包/類
public AppointmentMailer(Integer apptNo, Demographic demographic) {
this.mailSender = (MailSender) SpringUtils.getBean("asyncMailSender");
this.message = null;
this.msgTextTemplate = new StringBuilder();
this.apptNo = apptNo;
this.demographic = demographic;
}
示例11: notificationsTask
import org.springframework.mail.MailSender; //導入依賴的package包/類
private SimpleTask notificationsTask() {
return context -> {
MailSender mailSender = context.service(MailSender.class);
StreamItemRepository streamItemRepository = context.service(StreamItemRepository.class);
String itemId = context.property(NewMarkerFlow.itemId);
Optional.ofNullable(streamItemRepository
.findOne(itemId))
.ifPresent(sendMailToAuthor(mailSender,
context.property(username),
itemId,
context.property(markerType)));
};
}
示例12: createPasswordService
import org.springframework.mail.MailSender; //導入依賴的package包/類
private PasswordService createPasswordService(final String newPassword, final PasswordEncoder passwordEncoder, final UserRepository userRepository, final MailSender mailSender) {
return new PasswordService(passwordEncoder, userRepository, mailSender) {
@Override
public String newRandomPassword() {
return newPassword;
}
};
}
示例13: mailSender
import org.springframework.mail.MailSender; //導入依賴的package包/類
@Bean
public MailSender mailSender() {
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost(smtpHost);
sender.setPort(smtpPort);
sender.setUsername(smtpUsername);
sender.setPassword(smtpPassword);
return sender;
}
示例14: setup
import org.springframework.mail.MailSender; //導入依賴的package包/類
@Before
public void setup() {
repository = mock(InstanceRepository.class);
when(repository.find(instance.getId())).thenReturn(Mono.just(instance));
sender = mock(MailSender.class);
notifier = new MailNotifier(sender, repository);
notifier.setTo(new String[]{"[email protected]"});
notifier.setCc(new String[]{"[email protected]"});
notifier.setFrom("SBA <[email protected]>");
notifier.setSubject("#{instance.id} is #{event.statusInfo.status}");
}
示例15: UnsafeGroupMembershipManager
import org.springframework.mail.MailSender; //導入依賴的package包/類
protected UnsafeGroupMembershipManager(final CourseMembershipDbLoader setCourseMembershipLoader,
final UserDbLoader setUserLoader, final VelocityEngine setVelocityEngine,
final MailSender setMailSender, final SimpleMailMessage setMessageTemplate) {
this.courseMembershipLoader = setCourseMembershipLoader;
this.velocityEngine = setVelocityEngine;
this.userLoader = setUserLoader;
this.mailSender = setMailSender;
this.messageTemplate = setMessageTemplate;
}