当前位置: 首页>>代码示例>>Java>>正文


Java MailSender类代码示例

本文整理汇总了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);
    }
  };
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:25,代码来源:NewMarkerFlow.java

示例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);
    }
  });

}
 
开发者ID:adrobisch,项目名称:putput,代码行数:23,代码来源:NewItemFlow.java

示例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");
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:21,代码来源:SendConfirmationTask.java

示例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)));
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:23,代码来源:PasswordServiceTest.java

示例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;
}
 
开发者ID:Clemens85,项目名称:runningdinner,代码行数:21,代码来源:EmailService.java

示例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;
}
 
开发者ID:Clemens85,项目名称:runningdinner,代码行数:24,代码来源:EmailService.java

示例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);
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:21,代码来源:GavinJobFactory.java

示例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;
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:12,代码来源:MailConfig.java

示例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
        }
    };
}
 
开发者ID:JavaTrainingCourse,项目名称:obog-manager,代码行数:16,代码来源:MailConfig.java

示例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;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:8,代码来源:AppointmentMailer.java

示例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)));
  };
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:15,代码来源:NewMarkerFlow.java

示例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;
    }
  };
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:9,代码来源:PasswordServiceTest.java

示例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;
}
 
开发者ID:IBM-Cloud,项目名称:session-questions,代码行数:10,代码来源:Config.java

示例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}");
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:14,代码来源:MailNotifierTest.java

示例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;
}
 
开发者ID:rnicoll,项目名称:learn_syllabus_plus_sync,代码行数:10,代码来源:UnsafeGroupMembershipManager.java


注:本文中的org.springframework.mail.MailSender类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。