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


Java MailConstants类代码示例

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


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

示例1: run

import org.apache.axis2.transport.mail.MailConstants; //导入依赖的package包/类
public void run() {
    Map<String, String> headerMap = new HashMap<String, String>();
    headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject);
    OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(
            BaseConstants.DEFAULT_TEXT_WRAPPER, null);
    payload.setText(body);
    try {
        ServiceClient serviceClient;
        ConfigurationContext configContext = EmailServiceDataHolder.getInstance()
                .getConfigurationContextService().getClientConfigContext();
        //Set configuration service client if available, else create new service client
        if (configContext != null) {
            serviceClient = new ServiceClient(configContext, null);
        } else {
            serviceClient = new ServiceClient();
        }
        Options options = new Options();
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
        options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT,
                MailConstants.TRANSPORT_FORMAT_TEXT);
        options.setTo(new EndpointReference(EMAIL_URI_SCHEME + to));
        serviceClient.setOptions(options);
        serviceClient.fireAndForget(payload);
        log.debug("Sending confirmation mail to " + to);
    } catch (AxisFault e) {
        log.error("Error in delivering the message, subject: '" + subject + "', to: '" + to + "'", e);
    }
}
 
开发者ID:wso2-incubator,项目名称:iot-server-appliances,代码行数:30,代码来源:EmailServiceProviderImpl.java

示例2: sendMimeMessage

import org.apache.axis2.transport.mail.MailConstants; //导入依赖的package包/类
/**
 *
 * @param configContext ConfigurationContext
 * @param message Mail body
 * @param subject Mail Subject
 * @param toAddress email to address
 * @throws RegistryException Registry exception
 */
public void sendMimeMessage(ConfigurationContext configContext, String message, String subject, String toAddress) throws  RegistryException {
    Properties props = new Properties();
    if (configContext != null && configContext.getAxisConfiguration().getTransportOut("mailto") != null) {
        List<Parameter> params = configContext.getAxisConfiguration().getTransportOut("mailto").getParameters();
        for (Parameter parm: params) {
            props.put(parm.getName(), parm.getValue());
        }
    }
    if (threadPoolExecutor == null) {
        threadPoolExecutor = new ThreadPoolExecutor(MIN_THREAD, MAX_THREAD, DEFAULT_KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(1000));
    }
    String smtpFrom = props.getProperty(MailConstants.MAIL_SMTP_FROM);

    try {
        smtpFromAddress = new InternetAddress(smtpFrom);
    } catch (AddressException e) {
        log.error("Error in retrieving smtp address");
        throw new RegistryException("Error in transforming smtp address");
    }
    final String smtpUsername = props.getProperty(MailConstants.MAIL_SMTP_USERNAME);
    final String smtpPassword = props.getProperty(MailConstants.MAIL_SMTP_PASSWORD);
    if (smtpUsername != null && smtpPassword != null) {
        MimeEmailMessageHandler.session = Session.getInstance(props, new Authenticator() {
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(smtpUsername, smtpPassword);
            }
        });
    } else {
        MimeEmailMessageHandler.session = Session.getInstance(props);
    }
    threadPoolExecutor.submit(new EmailSender(toAddress, subject, message.toString(), "text/html"));
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:41,代码来源:MimeEmailMessageHandler.java

示例3: getEmailSubject

import org.apache.axis2.transport.mail.MailConstants; //导入依赖的package包/类
/**
 *
 * @param message Message Object
 * @param path  Registry path
 * @param event Event name
 * @return  Mail Subject
 */
public String getEmailSubject(Message message, String path,String event){
    String mailHeader = message.getProperty(MailConstants.MAIL_HEADER_SUBJECT);
    if (mailHeader == null && (path == null || path.length() == 0)) {
        mailHeader =  "[" + event + "]";
    } else if (mailHeader == null) {
        mailHeader ="[" + event + "] at path: " + path;
    }
    return mailHeader;
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:17,代码来源:MimeEmailMessageHandler.java

示例4: sendMessage

import org.apache.axis2.transport.mail.MailConstants; //导入依赖的package包/类
/**
 * Logic for sending email on publisher event from Notification Management component
 *
 * @param publisherEvent Publisher event from publisher. Includes event name and properties
 * @throws NotificationManagementException
 */
@Override
public void sendMessage(PublisherEvent publisherEvent) throws NotificationManagementException {
    // publisher event will not be null, since it is handled by the mgt component
    EmailSubscription subscription = subscriptionMap.get(publisherEvent.getEventName());

    // Message sending will only be done if there is a subscription on this module
    if (subscription != null) {
        List<EmailEndpointInfo> endpointInfoList = new ArrayList<EmailEndpointInfo>(subscription.getEmailEndpointInfoList());

        PrivilegedCarbonContext.startTenantFlow();
        // Send mails for each and every subscribed endpoint of the subscription
        for (EmailEndpointInfo endpointInfo : endpointInfoList) {
            Map<String, String> headerMap = new HashMap<String, String>();

            headerMap.put(MailConstants.MAIL_HEADER_SUBJECT,
                    getSubject(subscription.getSubscriptionProperties(),
                            endpointInfo.getProperties(),
                            publisherEvent.getEventProperties()));
            // Read the template configured in endpoint information.
            String template = endpointInfo.getTemplate();
            // If there is no template defined in the endpoint. use default template for which is configured for
            // subscription.
            if (StringUtils.isEmpty(template)) {
                template = subscription.getMailTemplate();
            }
            // If still no template found. The message sending will be aborted to that
            // particular endpoint.
            if (template == null) {
                log.error("No template found to send email to " + endpointInfo.getEmailAddress() + "on event " +
                        publisherEvent.getEventName() + ", sending aborted");
                continue;
            }
            // Get the message which the place holders are replaced by configurations and
            // subscription properties.
            String message = getMessage(template,
                    subscription.getSubscriptionProperties(),
                    endpointInfo.getProperties(), publisherEvent.getEventProperties());
            OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(BaseConstants
                    .DEFAULT_TEXT_WRAPPER, null);
            payload.setText(message);
            ServiceClient serviceClient;
            ConfigurationContext configContext = CarbonConfigurationContextFactory.getConfigurationContext();
            try {
                if (configContext != null) {
                    serviceClient = new ServiceClient(configContext, null);
                } else {
                    serviceClient = new ServiceClient();
                }
                //setting properties for axis2 client
                Options options = new Options();
                options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
                options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
                options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT,
                        MailConstants.TRANSPORT_FORMAT_TEXT);
                options.setTo(new EndpointReference(EmailModuleConstants.MAILTO_LABEL +
                        endpointInfo.getEmailAddress()));
                serviceClient.setOptions(options);
                serviceClient.fireAndForget(payload);
                if (log.isDebugEnabled()) {
                    log.debug("Email has been sent to " + endpointInfo.getEmailAddress() + ", " +
                            "on event " + publisherEvent.getEventName());
                }
            } catch (AxisFault axisFault) {
                log.error("Error while sending email notification to address " + endpointInfo.
                        getEmailAddress() + "on event " + publisherEvent.getEventName(), axisFault);
            }
        }
        // Ultimately close tenant flow.
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:78,代码来源:EmailSendingModule.java

示例5: sendEmail

import org.apache.axis2.transport.mail.MailConstants; //导入依赖的package包/类
@Override
public void sendEmail() {

    Map<String, String> headerMap = new HashMap<String, String>();

    try {
        if (this.notification == null) {
            throw new IllegalStateException("Notification not set. " +
                    "Please set the notification before sending messages");
        }
        PrivilegedCarbonContext.startTenantFlow();
        if (notificationData != null) {
            String tenantDomain = notificationData.getDomainName();
            PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            carbonContext.setTenantDomain(tenantDomain, true);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("notification data not found. Tenant might not be loaded correctly");
            }
        }

        headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, this.notification.getSubject());

        OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(
                BaseConstants.DEFAULT_TEXT_WRAPPER, null);
        StringBuilder contents = new StringBuilder();
        contents.append(this.notification.getBody())
                .append(System.getProperty("line.separator"))
                .append(System.getProperty("line.separator"))
                .append(this.notification.getFooter());
        payload.setText(contents.toString());
        ServiceClient serviceClient;
        ConfigurationContext configContext = CarbonConfigurationContextFactory
                .getConfigurationContext();
        if (configContext != null) {
            serviceClient = new ServiceClient(configContext, null);
        } else {
            serviceClient = new ServiceClient();
        }
        Options options = new Options();
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
        options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT,
                MailConstants.TRANSPORT_FORMAT_TEXT);
        options.setTo(new EndpointReference("mailto:" + this.notification.getSendTo()));
        serviceClient.setOptions(options);
        log.info("Sending " + "user credentials configuration mail to " + this.notification.getSendTo());
        serviceClient.fireAndForget(payload);
        
        if (log.isDebugEnabled()) {
            log.debug("Email content : " + this.notification.getBody());
        }
        log.info("User credentials configuration mail has been sent to " + this.notification.getSendTo());
    } catch (AxisFault axisFault) {
        log.error("Failed Sending Email", axisFault);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }

}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:61,代码来源:DefaultEmailSendingModule.java

示例6: run

import org.apache.axis2.transport.mail.MailConstants; //导入依赖的package包/类
public void run() {

        Map<String, String> headerMap = new HashMap<String, String>();
        Map<String, String> userParams = new HashMap<String, String>();
        userParams.put("admin-name", userParameters.get("admin"));
        userParams.put("user-name", userParameters.get("userName"));
        userParams.put("domain-name", userParameters.get("tenantDomain"));
        userParams.put("first-name", userParameters.get("first-name"));
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);

            if (config.getSubject().length() == 0) {
                headerMap.put(MailConstants.MAIL_HEADER_SUBJECT,
                              EmailVerifierConfig.DEFAULT_VALUE_SUBJECT);

            } else {
                headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, replacePlaceHolders(
                        config.getSubject(), userParams));
            }
            String requestMessage = replacePlaceHolders(getRequestMessage(), userParams);

            OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(
                    BaseConstants.DEFAULT_TEXT_WRAPPER, null);
            payload.setText(requestMessage);
            ServiceClient serviceClient;
            ConfigurationContext configContext =
                    EmailVerificationServiceComponent.getConfigurationContext();
            if (configContext != null) {
                serviceClient = new ServiceClient(configContext, null);
            } else {
                serviceClient = new ServiceClient();
            }
            Options options = new Options();
            options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
            options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
            options.setProperty(
                    MailConstants.TRANSPORT_MAIL_FORMAT, MailConstants.TRANSPORT_FORMAT_TEXT);
            options.setTo(new EndpointReference("mailto:" + emailAddr));
            serviceClient.setOptions(options);
            serviceClient.fireAndForget(payload);
            log.debug("Sending confirmation mail to " + emailAddr);
            log.debug("Verification url : " + requestMessage);
            // Send the message

            log.debug("Sending confirmation mail to " + emailAddr + "DONE");
        } catch (AxisFault e) {
            log.error("Failed Sending Email", e);
        }  finally {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
 
开发者ID:wso2,项目名称:carbon-commons,代码行数:53,代码来源:EmailSender.java


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