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


Java JavaMailSender类代码示例

本文整理汇总了Java中org.springframework.mail.javamail.JavaMailSender的典型用法代码示例。如果您正苦于以下问题:Java JavaMailSender类的具体用法?Java JavaMailSender怎么用?Java JavaMailSender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JavaMailSender类属于org.springframework.mail.javamail包,在下文中一共展示了JavaMailSender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: javaMailService

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Bean
public JavaMailSender javaMailService() {
    JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();

    if (this.auth) {
        javaMailSender.setUsername(this.username);
        javaMailSender.setPassword(this.password);
    }

    Properties properties = new Properties();
    properties.setProperty("mail.transport.protocol", this.protocol);
    properties.setProperty("mail.smtp.auth", Boolean.toString(this.auth));
    properties.setProperty("mail.smtp.starttls.enable", Boolean.toString(this.starttls));
    properties.setProperty("mail.debug", Boolean.toString(this.debug));
    properties.setProperty("mail.smtp.host", this.host);
    properties.setProperty("mail.smtp.port", Integer.toString(this.port));
    properties.setProperty("mail.smtp.ssl.trust", this.trust);
    javaMailSender.setJavaMailProperties(properties);

    return javaMailSender;
}
 
开发者ID:modum-io,项目名称:tokenapp-backend,代码行数:22,代码来源:MailService.java

示例2: getMailSender

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
/**
 * Return the {@link JavaMailSender} built from the given node.
 * 
 * @param node
 *            The node holding the SMTP configuration.
 * @return the {@link JavaMailSender} built from the given node.
 */
@CacheResult(cacheName = "plugin-data")
public JavaMailSender getMailSender(@CacheKey final String node) {
	final JavaMailSenderImpl mail = new JavaMailSenderImpl();
	final Map<String, String> parameters = pvResource.getNodeParameters(node);
	mail.setUsername(parameters.get(PARAMETER_USER));
	mail.setPassword(parameters.get(PARAMETER_PASSWORD));
	mail.setHost(parameters.get(PARAMETER_HOST));
	mail.setPort(Optional.ofNullable(parameters.get(PARAMETER_PORT)).map(Integer::valueOf).orElse(125));
	mail.setDefaultEncoding("UTF-8");

	final Properties properties = new Properties();
	properties.put("mail.smtp.auth", Boolean.TRUE);
	properties.put("mail.smtp.starttls.enable", Boolean.TRUE);
	properties.put("mail.smtp.quitwait", Boolean.FALSE);
	properties.put("mail.smtp.socketFactory.fallback", Boolean.FALSE);

	mail.setJavaMailProperties(properties);
	return mail;
}
 
开发者ID:ligoj,项目名称:plugin-mail-smtp,代码行数:27,代码来源:SmtpPluginResource.java

示例3: sendPasswordResetMail

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Async
public void sendPasswordResetMail(String target,String reseturl,JavaMailSender javaMailSender) throws InterruptedException  {
	try {
		MimeMessage mimeMsg = javaMailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8");
		String content = (String) PropertyPlaceholder.getProperty("mail.template");
		content = content.replace("{reseturl}", reseturl);
		helper.setText(content, true);
		helper.setTo(new String[]{target});
		String title = (String) PropertyPlaceholder.getProperty("mail.title");
		helper.setSubject(title); 
		String authormail = (String) PropertyPlaceholder.getProperty("mail.sendfrom");
		String authorname = (String) PropertyPlaceholder.getProperty("mail.sendname");
		helper.setFrom(authormail,authorname);
		javaMailSender.send(mimeMsg);
		log.info("Password Reset Mail has been send to "+target);
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:zjlywjh001,项目名称:PhrackCTF-Platform-Personal,代码行数:21,代码来源:MailUtil.java

示例4: mailSender

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Bean
public JavaMailSender mailSender() {
	JavaMailSenderImpl sender = new JavaMailSenderImpl();
	sender.setHost(this.properties.getHost());
	sender.setPort(this.properties.getPort());
	sender.setUsername(this.properties.getUsername());
	sender.setPassword(this.properties.getPassword());
	sender.setProtocol(this.properties.getProtocol());
	sender.setDefaultEncoding(this.properties.getDefaultEncoding().name());
	// extra properties
	if (!this.properties.getProperties().isEmpty()) {
		Properties mailProperties = new Properties();
		mailProperties.putAll(this.properties.getProperties());
		sender.setJavaMailProperties(mailProperties);
	}
	return sender;
}
 
开发者ID:mychalvlcek,项目名称:spring-rest-skeleton,代码行数:18,代码来源:EmailConfiguration.java

示例5: build

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
private static JavaMailSender build(MailConfigSource config) {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    
    mailSender.setDefaultEncoding(StandardCharsets.UTF_8.name());
    mailSender.setHost(config.mailServer().getHost());
    mailSender.setPort(config.mailServer().getPort());
    
    JProps mailProps = new JProps(mailSender.getJavaMailProperties());
    configureTransport(config, mailProps);
    config.username().ifPresent(
            u -> configureAuthentication(config, u, mailSender, mailProps));
    if (MailProtocol.smtps.equals(config.protocol())) {
        configureTls(config, mailProps);
    }
    
    return mailSender;
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:18,代码来源:MailClientAdapter.java

示例6: javaMailSender

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Bean
public JavaMailSender javaMailSender() {
	JavaMailSenderImpl mailSender = new JavaMailSenderImpl();

	Properties mailProperties = new Properties();
	mailProperties.put("mail.smtp.auth", auth);
	mailProperties.put("mail.smtp.starttls.enable", starttls);
	mailSender.setJavaMailProperties(mailProperties);
	mailSender.setHost(host);
	mailSender.setPort(port);
	mailSender.setProtocol(protocol);
	mailSender.setUsername(username);
	mailSender.setPassword(password);

	return mailSender;
}
 
开发者ID:oojorgeoo89,项目名称:QuizZz,代码行数:17,代码来源:MailConfig.java

示例7: createHtmlEmail

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
private static void createHtmlEmail(int i){
    try {
        JavaMailSender sender = getEmailSender();

        MimeMessage message = sender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setTo("[email protected]");
        helper.setFrom("[email protected]");
        helper.setSubject("Test-Mail " + i);
        helper.setText("<html><head></head><body>This is the test mail number " + i + "</body>", true);

        sender.send(message);
    } catch (MessagingException e){
        throw new RuntimeException("Failed to create mail", e);
    }
}
 
开发者ID:gessnerfl,项目名称:fake-smtp-server,代码行数:17,代码来源:TestDataCreator.java

示例8: javaMailSender

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Bean
public JavaMailSender javaMailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();

    Properties mailProperties = new Properties();
    mailProperties.put("mail.smtp.auth", auth);
    mailProperties.put("mail.smtp.starttls.enable", starttls);
    mailProperties.put("mail.smtp.starttls.required", startlls_required);
    mailProperties.put("mail.smtp.socketFactory.port", socketPort);
    mailProperties.put("mail.smtp.debug", debug);
    mailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    mailProperties.put("mail.smtp.socketFactory.fallback", fallback);

    mailSender.setJavaMailProperties(mailProperties);
    mailSender.setHost(host);
    mailSender.setPort(port);
    mailSender.setProtocol(protocol);
    mailSender.setUsername(username);
    mailSender.setPassword(password);
    return mailSender;
}
 
开发者ID:Exercon,项目名称:AntiSocial-Platform,代码行数:22,代码来源:MailConfiguration.java

示例9: mailTo

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Async
public void mailTo(String[] targetuser,String title,String content,JavaMailSender javaMailSender) {//邮件功能
	try {
		MimeMessage mimeMsg = javaMailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8");
		helper.setText(content, true);
		helper.setBcc(targetuser);
		helper.setSubject(title);
		String authormail = (String) PropertyPlaceholder.getProperty("mail.sendfrom");
		String authorname = (String) PropertyPlaceholder.getProperty("mail.sendname");
		helper.setFrom(authormail,authorname);
		javaMailSender.send(mimeMsg);
		log.info("Mail send to "+Arrays.toString(targetuser));
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:zjlywjh001,项目名称:PhrackCTF-Platform-Team,代码行数:18,代码来源:MailUtil.java

示例10: javaMailSender

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Bean
public JavaMailSender javaMailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost(config.getSmtpHost());
    mailSender.setPort(config.getSmtpPort());
    mailSender.setProtocol(config.getSmtpProtocol());
    mailSender.setUsername(config.getSmtpUsername());
    mailSender.setPassword(config.getSmtpPassword());
    mailSender.setDefaultEncoding("UTF-8");
    if ("smtps".equalsIgnoreCase(config.getSmtpProtocol())) {
        Properties mailProperties = new Properties();
        mailProperties.setProperty("mail.smtps.auth", "true");
        mailProperties.setProperty("mail.smtp.ssl.enable", "true");
        mailProperties.setProperty("mail.transport.protocol", "smtps");
        mailProperties.setProperty("mail.debug", "true");
        mailProperties.setProperty("mail.mime.charset", "utf8");
        mailSender.setJavaMailProperties(mailProperties);
    }
    return mailSender;
}
 
开发者ID:mattpwest,项目名称:entelect-spring-webapp-template,代码行数:21,代码来源:MailConfig.java

示例11: CaptchaService

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Autowired
public CaptchaService(UserInfoValidator userInfoValidator, LsPushProperties lsPushProperties,
    JavaMailSender mailSender, TemplateEngine templateEngine, ObjectMapper objectMapper,
    UserRepository userRepo) {
    mUserInfoValidator = userInfoValidator;
    serverName = lsPushProperties.getServerName();
    serverUrl = lsPushProperties.getServerUrl();
    serverEmail = lsPushProperties.getServerEmail();
    mMailSender = mailSender;
    mTemplateEngine = templateEngine;
    mObjectMapper = objectMapper;
    mUserRepo = userRepo;
    mAuthCodeMap = CacheBuilder.newBuilder()
        .initialCapacity(100)
        .maximumSize(500)
        .expireAfterWrite(30, TimeUnit.MINUTES)
        .build();

    mStringFunnel = (Funnel<String>) (from, into) -> into.putString(from, StandardCharsets.UTF_8);
    resetBloomFilter();
}
 
开发者ID:TomeOkin,项目名称:LsPush-Server,代码行数:22,代码来源:CaptchaService.java

示例12: getMailSender

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
public JavaMailSender getMailSender() {
    if (mailSender == null) {
        final JavaMailSenderImpl impl = new JavaMailSenderImpl();
        impl.setHost(smtpServer);
        impl.setPort(smtpPort);
        final Properties properties = new Properties();
        if (StringUtils.isNotEmpty(smtpUsername)) {
            // Use authentication
            properties.setProperty("mail.smtp.auth", "true");
            impl.setUsername(smtpUsername);
            impl.setPassword(smtpPassword);
        }
        if (smtpUseTLS) {
            properties.setProperty("mail.smtp.starttls.enable", "true");
        }
        impl.setJavaMailProperties(properties);
        mailSender = impl;
    }
    return mailSender;
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:21,代码来源:MailSettings.java

示例13: sendMail

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
private Consumer<UserEntity> sendMail(JavaMailSender mailSender, final MessageEntity messageEntity) {
  return foundUser -> {
    if (ofNullable(foundUser.getEmail()).isPresent()) {
      MimeMessagePreparator preparator = mimeMessage -> {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
        message.setFrom("[email protected]");
        message.setSubject("New message from @" + messageEntity.getFrom());
        message.setTo(foundUser.getEmail());
        
        String textContent = new MailTemplates()
                .create("message")
                .data("text", messageEntity.getText())
                .getText();

        String htmlContent = new MailTemplates()
                .create("message.html")
                .data("text", htmlContent(messageEntity))
                .getText();

        message.setText(textContent, htmlContent);
      };
      
      mailSender.send(preparator);
    }
  };
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:27,代码来源:NewMessageFlow.java

示例14: EmailService

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
public EmailService(JavaMailSender mailSender, String supportEmail, String personalName)
        throws UnsupportedEncodingException {
    if(mailSender==null) {
        throw new IllegalArgumentException("EmailService constructor contains a null JavaMailSender argument");
    }
    if(supportEmail==null) {
        throw new IllegalArgumentException("EmailService constructor contains a null String argument");
    }
    Address[] temp = null;
    try {
        temp = new Address[] {new InternetAddress(supportEmail, personalName)};
    } catch (IllegalArgumentException e) {
        LOGGER.error(e);
    }

    this.senderAddresses = temp;
    this.mailSender = mailSender;
}
 
开发者ID:trustedanalytics,项目名称:user-management,代码行数:19,代码来源:EmailService.java

示例15: tryLookup

import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
/**
 * Try to perform the lookup of the email service. This is called during
 * configuration so that any failure happens at a useful, predictable time.
 */
@PostConstruct
public void tryLookup() {
	if (!isAvailable()) {
		log.warn("no mail support; disabling email dispatch");
		sender = null;
		return;
	}
	try {
		if (sender instanceof JavaMailSender)
			((JavaMailSender) sender).createMimeMessage();
	} catch (Throwable t) {
		log.warn("sender having problems constructing messages; "
				+ "disabling...", t);
		sender = null;
	}
}
 
开发者ID:apache,项目名称:incubator-taverna-server,代码行数:21,代码来源:EmailDispatcher.java


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