org.apache.camel.component.mail.MailComponent Java Examples

The following examples show how to use org.apache.camel.component.mail.MailComponent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CamelRoute.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Produces
MailComponent smtp() {
    MailComponent mail = new MailComponent(getContext());
    Session session = Session.getInstance(new Properties());
    mail.getConfiguration().setSession(session);
    return mail;
}
 
Example #2
Source File: MailComponentAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Lazy
@Bean({"imap-component", "imaps-component", "pop3-component", "pop3s-component", "smtp-component", "smtps-component"})
@ConditionalOnMissingBean(MailComponent.class)
public MailComponent configureMailComponent() throws Exception {
    MailComponent component = new MailComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, component,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (ComponentCustomizer<MailComponent> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.mail.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.mail.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure component {}, with customizer {}",
                        component, customizer);
                customizer.customize(component);
            }
        }
    }
    return component;
}
 
Example #3
Source File: EMailComponent.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
protected Optional<Component> createDelegateComponent(ComponentDefinition definition, Map<String, Object> options) {
    String protocol = getProtocol();
    if (protocol == null) {
        throw new IllegalStateException("No protocol specified for email component");
    }

    MailConfiguration configuration = new MailConfiguration(getCamelContext());
    configuration.configureProtocol(protocol);
    configuration.setHost(getHost());
    configuration.setPort(getPort());
    configuration.setUsername(getUsername());
    configuration.setPassword(getPassword());
    configuration.setUnseen(isUnseenOnly());

    if (getFolderName() != null) {
        configuration.setFolderName(getFolderName());
    }

    Map<String, Object> resolvedOptions = bundleOptions();
    SSLContextParameters sslContextParameters = EMailUtil.createSSLContextParameters(resolvedOptions);
    if (sslContextParameters != null) {
        configuration.setSslContextParameters(sslContextParameters);
    } else if (SecureType.STARTTLS.equals(secureType)) {
        Properties properties = new Properties();
        properties.put("mail." + protocol + ".starttls.enable", "true");
        properties.put("mail." + protocol + ".starttls.required", "true");
        configuration.setAdditionalJavaMailProperties(properties);
    }

    configuration.setFetchSize(getMaxResults());

    // Decode mime headers like the subject from Quoted-Printable encoding to normal text
    configuration.setMimeDecodeHeaders(true);

    MailComponent component = new MailComponent(getCamelContext());
    component.setConfiguration(configuration);
    return Optional.of(component);
}