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