當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。