【问题标题】:How to format Email body using "text/plain" as content type in wso2 EI 6.3.0?如何在 wso2 EI 6.3.0 中使用“text/plain”作为内容类型来格式化电子邮件正文?
【发布时间】:2019-11-06 04:18:38
【问题描述】:

我在 wso2 EI 中发送电子邮件通知。我需要在该电子邮件正文中包含传入请求(即 XML)。如果我将内容类型用作“text/html;charset=UTF-8”,则不会获取 xml 内容。但我使用“text/plain; charset=UTF-8”作为内容类型,完全得到了我想要的。但我无法在使用“text/plain”时格式化这些电子邮件正文。 谁能帮我发送“带有 XML 内容的格式化电子邮件正文”? 笔记: 电子邮件发送成功并获得我想要的内容。但我无法格式化粗体、斜体等电子邮件正文。

使用 Gmail 连接器发送邮件

API-代码:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/sendMail" name="MailSenderAPI" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST">
        <inSequence>
            <log level="custom">
                <property name="WelocmeLogger" value="======MailSenderAPI Started====="/>
            </log>
            <property description="Incoming request" expression="$body/*" name="InputRequest" />
            <log level="custom">
            <property expression="$body/*" name="RequestPayload"/>
            </log>
            <property description="ASGReadFromEmailBody-ServiceConfig" expression="get-property('QRSag_GmailConfiguration')" name="tokenConfig" scope="axis2" type="OM"/>
            <property description="accessToken" expression="$axis2:tokenConfig//*[local-name()='accessToken']" name="accessToken" scope="default" type="STRING"/>
            <property description="userId" expression="$axis2:tokenConfig//*[local-name()='userId']" name="userId" scope="default" type="STRING"/>
            <property description="refreshToken" expression="$axis2:tokenConfig//*[local-name()='refreshToken']" name="refreshToken" scope="default" type="STRING"/>
            <property description="registryPath" expression="$axis2:tokenConfig//*[local-name()='registryPath']" name="registryPath" scope="default" type="STRING"/>
            <property description="clientSecret" expression="$axis2:tokenConfig//*[local-name()='clientSecret']" name="clientSecret" scope="default" type="STRING"/>
            <property description="clientId" expression="$axis2:tokenConfig//*[local-name()='clientId']" name="clientId" scope="default" type="STRING"/>
            <property description="apiUrl" expression="$axis2:tokenConfig//*[local-name()='apiUrl']" name="apiUrl" scope="default" type="STRING"/>
            <property description="registryPath" expression="$axis2:tokenConfig//*[local-name()='registryPath']" name="registryPath" scope="default" type="STRING"/>
            <class name="com.qrsolutions.in.EmailContentMaker"/>
            <property description="mailingList" expression="get-property('QRSAG-CommonMailListing')" name="GetGamilID" scope="default" type="STRING"/>
             <!-- <property description="contentType" name="contentType" scope="default" type="STRING" value="text/html; charset=UTF-8"/>  -->
              <property description="contentType" name="contentType" scope="default" type="STRING" value="text/plain; charset=UTF-8"/>  

            <property name="Subject" scope="default" type="STRING" value="TEST:ASG-Lead Duplicate Records"/>
            <!-- <log level="custom">
                <property expression="$ctx:emailContent" name="EmailContent"/>
            </log> -->
            <gmail.init>
                <userId>me</userId>
                <accessToken>{$ctx:accessToken}</accessToken>
                <apiUrl>{$ctx:apiUrl}</apiUrl>
                <clientId>{$ctx:clientId}</clientId>
                <clientSecret>{$ctx:clientSecret}</clientSecret>
                <refreshToken>{$ctx:refreshToken}</refreshToken>
                <accessTokenRegistryPath>{$ctx:registryPath}</accessTokenRegistryPath>
            </gmail.init>
            <log level="full"/>
            <gmail.sendMail>
                <to>{$ctx:GetGamilID}</to>
                <subject>{$ctx:Subject}</subject>
                <from>asg.test@qrsolutions.com.au</from>
                <messageBody>{$ctx:emailContent}</messageBody>
                <contentType>{$ctx:contentType}</contentType>
            </gmail.sendMail>
            <log level="custom">
            <property name="Response" value="mail Sent Successfully"></property>
            </log>
            <payloadFactory media-type="json">
             <format>{"MailStatus":$1,"Message":"$2"}</format>
               <args>
                 <arg value="true"/>
                   <arg value="mail Sent Successfully"/>
               </args>
              </payloadFactory>
              <respond/>
            <!-- <property expression="get-property('GetGamilID')" name="To" scope="default" type="STRING"/>
            <property name="From" scope="default" type="STRING" value="asg.test@qrsolutions.com.au"/>
                <class name="com.qrsolutions.in.GmailSender"/>
                 <log level="custom">
                <property name="LoggerText" value="===Process Completed==="/>
            </log> -->
        </inSequence>
        <outSequence/>
        <faultSequence>
        <log level="custom">
        <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"></property>
        </log>
        <payloadFactory media-type="json">
             <format>{"MailStatus":$1,"Message":"$2"}</format>
               <args>
                 <arg value="false"/>
                   <arg expression="get-property('ERROR_MESSAGE')"/>
               </args>
              </payloadFactory>
              <respond/>
        </faultSequence>
    </resource>
</api>

EmailContentmaker-代码:

```package com.qrsolutions.in;

import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;

import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;

public class EmailContentMaker extends AbstractMediator{

    @Override
    public boolean mediate(MessageContext context) {
        System.out.println("===Inside EmailContentMaker Class Mediator===");
        String InputRequest = checkNull((String) context.getProperty("InputRequest"));
        try{

        context.setProperty("emailContent", "Hi Team," +"\n\nWe are facing issue in Lead Process and \n\n" + "Request:" + "\n\n" + InputRequest
                + "\n\n" +"Let us know if you have any concerns.\n\nCheers,\nIntegration Team.");
        System.out.println("EmailContent: "+context.getProperty("emailContent"));
        }catch(Exception e)
        {
            e.printStackTrace();
            System.out.println("Reason for Exception:" +e.getMessage());
        }
        return true;
    }
    public static String checkNull(String input) {
        String retValue = input == null ? "" : input.equalsIgnoreCase("null") ? "" : input.trim();
        return retValue;
    }



}```

请求:

<InputData>
    <id>123</id>
    <name>JustinTest</name>
    <email>testMail@gmail.com</email>
</InputData>

电子邮件正文中的预期输出:

Hi Team,

We are facing issue in Lead Process.
Request:
<InputData>
        <id>123</id>
        <name>JustinTest</name>
        <email>testMail@gmail.com</email>
</InputData>

Let us know if you have any concerns.

Cheers,
Integration Team.

--

【问题讨论】:

    标签: java gmail wso2esb wso2ei


    【解决方案1】:

    也许,你应该“...使用内容类型作为”text/html; charset=UTF-8".." 并在您的 EmailContentMaker 中添加一些 XML 转义特殊字符?您的 xml 将在您的消息中被视为格式化的 XML 文本。

    【讨论】:

      猜你喜欢
      • 2014-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-06
      • 2015-07-20
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      相关资源
      最近更新 更多