本文整理汇总了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;
}