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


Java JavaMailSenderImpl.setSession方法代码示例

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


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

示例1: mailSender

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
@Bean
public JavaMailSenderImpl mailSender() {
	JavaMailSenderImpl sender = new JavaMailSenderImpl();
	if (this.session != null) {
		sender.setSession(this.session);
	}
	else {
		applyProperties(sender);
	}
	return sender;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:MailSenderAutoConfiguration.java

示例2: createInstance

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
@Override
protected  Object createInstance() throws Exception {
    // Retrieve "mail.*" properties from the configuration system and construct a Properties object
	Properties properties = new Properties();
	Properties configProps = ConfigContext.getCurrentContextConfig().getProperties();
	LOG.debug("createInstance(): collecting mail properties.");
	for (Object keyObj : configProps.keySet()) {
	    if (keyObj instanceof String) {
	    	String key = (String)keyObj;
	    	if (key.startsWith(MAIL_PREFIX)){
	    		properties.put(key, configProps.get(key));
	    	}
	    }
	}
	
	// Construct an appropriate Java Mail Session
	// If username and password properties are found, construct a Session with SMTP authentication
	String username = properties.getProperty(USERNAME_PROPERTY);
	String password = properties.getProperty(PASSWORD_PROPERTY);
	if (username != null && password != null) {
		mailSession = Session.getInstance(properties, new SimpleAuthenticator(username, password));
		LOG.info("createInstance(): Initializing mail session using SMTP authentication.");
	} else {
		mailSession = Session.getInstance(properties);
		LOG.info("createInstance(): Initializing mail session. No SMTP authentication.");
	}
	
	// Construct and return a Spring Java Mail Sender
	JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
	LOG.debug("createInstance(): setting SMTP host.");
	mailSender.setHost(properties.getProperty(HOST_PROPERTY));
	if (properties.getProperty(PORT_PROPERTY) != null) {
		LOG.debug("createInstance(): setting SMTP port.");
		int smtpPort = Integer.parseInt(properties.getProperty(PORT_PROPERTY).trim());
		mailSender.setPort(smtpPort);
	}
       String protocol = properties.getProperty(PROTOCOL_PROPERTY);
       if (StringUtils.isNotBlank(protocol)) {
           LOG.debug("createInstance(): setting mail transport protocol = " + protocol);
           mailSender.setProtocol(protocol);
       }
	mailSender.setSession(mailSession);
	
	LOG.info("createInstance(): Mail Sender Factory Bean initialized.");
	return mailSender;
   }
 
开发者ID:kuali,项目名称:kc-rice,代码行数:47,代码来源:MailSenderFactoryBean.java

示例3: createSender

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
private ConfiguredSender createSender(MessageServerKey key) {
    final UISmtpServer server;
    if (key.getServerId() != null) {
        server = smtpServerService.getSmtpServer(key.getServerId());
    } else if (key.getSubsystemIdentifier() != null) {
        server = smtpServerService.getSmtpServerBySubsystemIdentifier(key.getSubsystemIdentifier());
    } else {
        server = null;
    }
    if (server != null) {
        boolean ssl = server.isSsl();
        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        Properties props = new Properties();
        props.put("mail.transport.protocol", "smtp");
        props.put("mail.host", server.getHost());
        props.put("mail.smtp.port", server.getPort() == null ? "25" : String.valueOf(server.getPort()));
        props.put("mail.user", server.getUsername());
        props.put("mail.password", server.getPassword());
        props.put("mail.debug", System.getProperty("mail.debug", "false"));
        props.put(ssl ? "mail.smtps.auth" : "mail.smtp.auth", "true");
        props.put("mail.transport.protocol", ssl ? "smtps" : "smtp");
        Session session = Session.getInstance(props, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(server.getUsername(), server.getPassword());
            }
        });
        sender.setSession(session);
        sender.setProtocol(ssl ? "smtps" : "smtp");
        return new ConfiguredSender(sender, server.getFrom());
    } else {
        logger.warn("No SMTP server found for key {}", key);
        return null;
    }
}
 
开发者ID:payneteasy,项目名称:superfly,代码行数:36,代码来源:JavaMailSenderPoolImpl.java


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