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


Java TransportStrategy类代码示例

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


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

示例1: initMailer

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
private void initMailer() {

        String host = appConfig.get(CONFIG_KEY_SMTP_HOST, "");
        int port = appConfig.getInt(CONFIG_KEY_SMTP_PORT, 465);
        String secure = appConfig.get(CONFIG_KEY_SMTP_SECURE, "tls");
        String username = appConfig.get(CONFIG_KEY_SMTP_USERNAME, "");
        String password = appConfig.get(CONFIG_KEY_SMTP_PASS, "");

        TransportStrategy transportStrategy = TransportStrategy.SMTP_PLAIN;
        if (secure.toLowerCase().equals("tls")) {

            transportStrategy = TransportStrategy.SMTP_TLS;
        } else if (secure.toLowerCase().equals("ssl")) {

            transportStrategy = TransportStrategy.SMTP_SSL;
        }

        mailer = new Mailer(new ServerConfig(host, port, username, password), transportStrategy);
        mailer.setSessionTimeout(30000);
//        mailer.setDebug(appConfig.getBool(CONFIG_KEY_APP_DEV_MODE, false));
    }
 
开发者ID:thundernet8,项目名称:Elune,代码行数:22,代码来源:MailMQServiceImpl.java

示例2: MailerRegularBuilder

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
/**
 * Sets defaults configured for SMTP host, SMTP port, SMTP username, SMTP password and transport strategy.
 * <p>
 * <strong>Note:</strong> Any builder methods invoked after this will override the default value.
 */
MailerRegularBuilder() {
	if (hasProperty(SMTP_HOST)) {
		withSMTPServerHost((String) getProperty(SMTP_HOST));
	}
	if (hasProperty(SMTP_PORT)) {
		withSMTPServerPort((Integer) getProperty(SMTP_PORT));
	}
	if (hasProperty(SMTP_USERNAME)) {
		withSMTPServerUsername((String) getProperty(SMTP_USERNAME));
	}
	if (hasProperty(SMTP_PASSWORD)) {
		withSMTPServerPassword((String) getProperty(SMTP_PASSWORD));
	}
	withTransportStrategy(TransportStrategy.SMTP);
	if (hasProperty(TRANSPORT_STRATEGY)) {
		withTransportStrategy((TransportStrategy) getProperty(TRANSPORT_STRATEGY));
	}
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:24,代码来源:MailerBuilder.java

示例3: createMailSession_MinimalConstructor_WithConfig_OPPORTUNISTIC_TLS

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
@Test
public void createMailSession_MinimalConstructor_WithConfig_OPPORTUNISTIC_TLS() {
	Properties properties = new Properties();
	properties.setProperty(OPPORTUNISTIC_TLS.key(), "false");
	ConfigLoader.loadProperties(properties, true);
	
	Mailer mailer = MailerBuilder.withTransportStrategy(TransportStrategy.SMTP).buildMailer();
	Session session = mailer.getSession();
	
	assertThat(session.getDebug()).isTrue();
	assertThat(session.getProperty("mail.smtp.host")).isEqualTo("smtp.default.com");
	assertThat(session.getProperty("mail.smtp.port")).isEqualTo("25");
	assertThat(session.getProperty("mail.transport.protocol")).isEqualTo("smtp");
	
	assertThat(session.getProperty("mail.smtp.starttls.enable")).isNull();
	assertThat(session.getProperty("mail.smtp.starttls.required")).isNull();
	assertThat(session.getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
	
	assertThat(session.getProperty("mail.smtp.username")).isEqualTo("username smtp");
	assertThat(session.getProperty("mail.smtp.auth")).isEqualTo("true");
	// the following two are because authentication is needed, otherwise proxy would be straightworward
	assertThat(session.getProperty("mail.smtp.socks.host")).isEqualTo("localhost");
	assertThat(session.getProperty("mail.smtp.socks.port")).isEqualTo("1081");
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:25,代码来源:MailerTest.java

示例4: createFullyConfiguredMailer

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
private Mailer createFullyConfiguredMailer(boolean authenticateProxy, String prefix, TransportStrategy transportStrategy) {
	MailerRegularBuilder mailerBuilder = MailerBuilder
			.withSMTPServer(prefix + "smtp host", 25, prefix + "username smtp", prefix + "password smtp")
			.withTransportStrategy(transportStrategy)
			.withDebugLogging(true);
	
	if (transportStrategy == SMTP_TLS) {
		if (authenticateProxy) {
			mailerBuilder
					.withProxy(prefix + "proxy host", 1080, prefix + "username proxy", prefix + "password proxy")
					.withProxyBridgePort(999);
		} else {
			mailerBuilder.withProxy(prefix + "proxy host", 1080);
		}
	} else if (transportStrategy == SMTPS) {
		mailerBuilder.clearProxy();
	}
	
	return mailerBuilder
			.withProperty("extra1", prefix + "value1")
			.withProperty("extra2", prefix + "value2")
			.buildMailer();
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:24,代码来源:MailerTest.java

示例5: loadPropertiesAddingMode

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
@Test
public void loadPropertiesAddingMode()
		throws Exception {
	String s1 = "simplejavamail.javaxmail.debug=true\n"
			+ "simplejavamail.transportstrategy=SMTPS";
	String s2 = "simplejavamail.defaults.to.name=To Default\n"
			+ "[email protected]";

	ConfigLoader.loadProperties(new ByteArrayInputStream(s1.getBytes()), false);
	ConfigLoader.loadProperties(new ByteArrayInputStream(s2.getBytes()), true);

	// some checks from the config file
	assertThat(ConfigLoader.getProperty(JAVAXMAIL_DEBUG)).isEqualTo(true);
	assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isEqualTo(TransportStrategy.SMTPS);
	// now check if the extra properties were added
	assertThat(ConfigLoader.getProperty(DEFAULT_TO_NAME)).isEqualTo("To Default");
	assertThat(ConfigLoader.getProperty(DEFAULT_TO_ADDRESS)).isEqualTo("[email protected]");
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:19,代码来源:ConfigLoaderTest.java

示例6: loadPropertiesFromObjectProperties

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
@Test
public void loadPropertiesFromObjectProperties()
		throws IOException {
	Properties source = new Properties();
	source.put("simplejavamail.javaxmail.debug", true);
	source.put("simplejavamail.transportstrategy", TransportStrategy.SMTPS);
	source.put("simplejavamail.smtp.host", "smtp.default.com");
	source.put("simplejavamail.smtp.port", 25);
	source.put("simplejavamail.smtp.username", "username");
	source.put("simplejavamail.smtp.password", "password");

	ConfigLoader.loadProperties(source, false);
	assertThat(ConfigLoader.getProperty(JAVAXMAIL_DEBUG)).isEqualTo(true);
	assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isSameAs(SMTPS);
	assertThat(ConfigLoader.getProperty(SMTP_HOST)).isEqualTo("smtp.default.com");
	assertThat(ConfigLoader.getProperty(SMTP_PORT)).isEqualTo(25);
	assertThat(ConfigLoader.getProperty(SMTP_USERNAME)).isEqualTo("username");
	assertThat(ConfigLoader.getProperty(SMTP_PASSWORD)).isEqualTo("password");
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:20,代码来源:ConfigLoaderTest.java

示例7: writeReport

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Render the report HTML using Jtwig and send the result to the recipient emails.
 */
@Override
public void writeReport(List<TestSuite> testSuites) throws IOException {
    if (testSuites == null) {
        testSuites = Collections.emptyList();
    }
    log.info("Sending report email for {} test suites", testSuites.size());
    List<TestSuiteModel> testList = new ArrayList<>(testSuites.size());
    boolean hasError = false;
    for (TestSuite testSuite : testSuites) {
        TestSuiteModel testSuiteModel = new TestSuiteModel(testSuite);
        hasError = hasError || !testSuiteModel.allPassed();
        testList.add(testSuiteModel);
    }
    JtwigTemplate template = JtwigTemplate.classpathTemplate("templates/email.twig");
    JtwigModel model = JtwigModel.newModel()
                                 .with("error", hasError)
                                 .with("testList", testList);
    String reportHtml = template.render(model);
    EmailBuilder emailBuilder = new EmailBuilder().from(senderName, fromEmail)
                                                  .replyTo(senderName, replyTo)
                                                  .subject("Validatar Report – " + (hasError ? "Test Errors" : "Tests Passed"))
                                                  .addHeader("X-Priority", 2)
                                                  .textHTML(reportHtml);
    for (String recipientEmail : recipientEmails) {
        emailBuilder.to(recipientEmail);
    }
    Email reportEmail = emailBuilder.build();
    ServerConfig mailServerConfig = new ServerConfig(smtpHost, smtpPort);
    Mailer reportMailer = new Mailer(mailServerConfig, TransportStrategy.SMTP_TLS);
    sendEmail(reportMailer, reportEmail);
    log.info("Finished sending report to recipients");
}
 
开发者ID:yahoo,项目名称:validatar,代码行数:38,代码来源:EmailFormatter.java

示例8: MailSender

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
public MailSender(@Nonnull final Session session,
				  @Nonnull final OperationalConfig operationalConfig,
				  @Nonnull final ProxyConfig proxyConfig,
				  @Nullable final TransportStrategy transportStrategy) {
	this.session = session;
	this.operationalConfig = operationalConfig;
	this.transportStrategy = transportStrategy;
	this.proxyServer = configureSessionWithProxy(proxyConfig, session, transportStrategy);
	init(operationalConfig);
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:11,代码来源:MailSender.java

示例9: configureSessionWithProxy

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
/**
 * If a {@link ProxyConfig} was provided with a host address, then the appropriate properties are set on the {@link Session}, overriding any SOCKS
 * properties already there.
 * <p>
 * These properties are <em>"mail.smtp(s).socks.host"</em> and <em>"mail.smtp(s).socks.port"</em>, which are set to "localhost" and {@link
 * ProxyConfig#getProxyBridgePort()}.
 *
 * @param proxyConfig       Proxy server details, optionally with username / password.
 * @param session           The session with properties to add the new configuration to.
 * @param transportStrategy Used to verify if the current combination with proxy is allowed (SMTP with SSL trategy doesn't support any proxy,
 *                          virtue of the underlying JavaMail framework). Can be omitted if the Session is presumed preconfigured.
 * @return null in case of no proxy or anonymous proxy, or a AnonymousSocks5Server proxy bridging server instance in case of authenticated proxy.
 */
private static AnonymousSocks5Server configureSessionWithProxy(@Nonnull final ProxyConfig proxyConfig,
															   @Nonnull final Session session,
															   @Nullable final TransportStrategy transportStrategy) {
	if (!proxyConfig.requiresProxy()) {
		LOGGER.debug("No proxy set, skipping proxy.");
	} else {
		if (transportStrategy == TransportStrategy.SMTPS) {
			throw new MailSenderException(MailSenderException.INVALID_PROXY_SLL_COMBINATION);
		}
		final Properties sessionProperties = session.getProperties();
		if (transportStrategy != null) {
			sessionProperties.put(transportStrategy.propertyNameSocksHost(), proxyConfig.getRemoteProxyHost());
			sessionProperties.put(transportStrategy.propertyNameSocksPort(), String.valueOf(proxyConfig.getRemoteProxyPort()));
		} else {
			LOGGER.debug("no transport strategy provided, expecting mail.smtp(s).socks.host and .port properties to be set to proxy " +
					"config on Session");
		}
		if (proxyConfig.requiresAuthentication()) {
			if (transportStrategy != null) {
				// wire anonymous proxy request to our own proxy bridge so we can perform authentication to the actual proxy
				sessionProperties.put(transportStrategy.propertyNameSocksHost(), "localhost");
				sessionProperties.put(transportStrategy.propertyNameSocksPort(), String.valueOf(proxyConfig.getProxyBridgePort()));
			} else {
				LOGGER.debug("no transport strategy provided but authenticated proxy required, expecting mail.smtp(s).socks.host and .port " +
						"properties to be set to localhost and port " + proxyConfig.getProxyBridgePort());
			}
			SocksProxyConfig socksProxyConfig = new SocksProxyConfig(proxyConfig.getRemoteProxyHost(), proxyConfig.getRemoteProxyPort(),
					proxyConfig.getUsername(), proxyConfig.getPassword(), proxyConfig.getProxyBridgePort());
			return new AnonymousSocks5Server(new AuthenticatingSocks5Bridge(socksProxyConfig), proxyConfig.getProxyBridgePort());
		}
	}
	return null;
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:47,代码来源:MailSender.java

示例10: logSession

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
/**
 * Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
 */
private static void logSession(final Session session) {
	final TransportStrategy transportStrategy = TransportStrategy.findStrategyForSession(session);
	final Properties properties = session.getProperties();
	final String sessionDetails = (transportStrategy != null) ? transportStrategy.toString(properties) : properties.toString();
	LOGGER.debug("starting mail with " + sessionDetails);
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:10,代码来源:MailSender.java

示例11: buildMailer

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
private static final Mailer buildMailer(String host, int port, String gMailAddress, String gMailPassword, TransportStrategy strategy) {
	return MailerBuilder
			.withSMTPServer(host, port, gMailAddress, gMailPassword)
			.withTransportStrategy(strategy)
			.withTransportModeLoggingOnly(LOGGING_MODE)
			.buildMailer();
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:8,代码来源:MailTestDemoApp.java

示例12: createMailSession_MinimalConstructor_WithConfig_OPPORTUNISTIC_TLS_Manually_Disabled

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
@Test
public void createMailSession_MinimalConstructor_WithConfig_OPPORTUNISTIC_TLS_Manually_Disabled() {
	Properties properties = new Properties();
	properties.setProperty(OPPORTUNISTIC_TLS.key(), "false");
	ConfigLoader.loadProperties(properties, true);
	
	TransportStrategy.SMTP.setOpportunisticTLS(true);
	
	Mailer mailer = MailerBuilder.withTransportStrategy(TransportStrategy.SMTP).buildMailer();
	Session session = mailer.getSession();
	
	assertThat(session.getDebug()).isTrue();
	assertThat(session.getProperty("mail.smtp.host")).isEqualTo("smtp.default.com");
	assertThat(session.getProperty("mail.smtp.port")).isEqualTo("25");
	assertThat(session.getProperty("mail.transport.protocol")).isEqualTo("smtp");
	
	assertThat(session.getProperty("mail.smtp.starttls.enable")).isEqualTo("true");
	assertThat(session.getProperty("mail.smtp.starttls.required")).isEqualTo("false");
	assertThat(session.getProperty("mail.smtp.ssl.trust")).isEqualTo("*");
	assertThat(session.getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("false");
	
	assertThat(session.getProperty("mail.smtp.username")).isEqualTo("username smtp");
	assertThat(session.getProperty("mail.smtp.auth")).isEqualTo("true");
	// the following two are because authentication is needed, otherwise proxy would be straightworward
	assertThat(session.getProperty("mail.smtp.socks.host")).isEqualTo("localhost");
	assertThat(session.getProperty("mail.smtp.socks.port")).isEqualTo("1081");
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:28,代码来源:MailerTest.java

示例13: parsePropertyValue

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
@Test
public void parsePropertyValue() {
	assertThat(ConfigLoader.parsePropertyValue("simple string value")).isEqualTo("simple string value");
	assertThat(ConfigLoader.parsePropertyValue("12345")).isEqualTo(12345);
	assertThat(ConfigLoader.parsePropertyValue("123d45")).isEqualTo("123d45");
	assertThat(ConfigLoader.parsePropertyValue("0")).isEqualTo(false);
	assertThat(ConfigLoader.parsePropertyValue("false")).isEqualTo(false);
	assertThat(ConfigLoader.parsePropertyValue("no")).isEqualTo(false);
	assertThat(ConfigLoader.parsePropertyValue("1")).isEqualTo(true);
	assertThat(ConfigLoader.parsePropertyValue("true")).isEqualTo(true);
	assertThat(ConfigLoader.parsePropertyValue("yes")).isEqualTo(true);
	assertThat(ConfigLoader.parsePropertyValue("yesno")).isEqualTo("yesno");
	assertThat(ConfigLoader.parsePropertyValue("SMTP")).isEqualTo(TransportStrategy.SMTP);
	assertThat(ConfigLoader.parsePropertyValue("SMTP_TLS")).isEqualTo(TransportStrategy.SMTP_TLS);
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:16,代码来源:ConfigLoaderTest.java

示例14: start

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
public void start() {
  mailer = new Mailer(
      new ServerConfig(
          Configuration.i.getSmtp().getHost(),
          Configuration.i.getSmtp().getPort(),
          Configuration.i.getSmtp().getUserName(),
          Configuration.i.getSmtp().getPassword()),
      TransportStrategy.SMTP_TLS);

  Properties props = new Properties();
  props.put("mail.smtp.localhost", "codeka.com.au");
  mailer.applyProperties(props);
}
 
开发者ID:codeka,项目名称:wwmmo,代码行数:14,代码来源:SmtpHelper.java

示例15: sendMail

import org.simplejavamail.mailer.config.TransportStrategy; //导入依赖的package包/类
@Override
public void sendMail() {
	new Mailer( new ServerConfig("smtp.host.com", 587),
                   TransportStrategy.SMTP_TLS
                   ).sendMail(email);
}
 
开发者ID:maugern,项目名称:jersey-skeleton,代码行数:7,代码来源:ConfirmationMail.java


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