WSO2 esb从电子邮件获取附件文件

问题描述 投票:1回答:1

我正在尝试使用WSO2 ESB来获取包含附件的电子邮件(流行邮件),并将所有这些附件添加到具有vfs的文件夹中。因此,我使用MailTransportListener创建了代理服务。我设法收到电子邮件,但我不知道如何从电子邮件中提取所有附件并将其保存到本地文件夹。这是我的代理服务。

感谢您的帮助。

尼古拉斯

`<proxy xmlns="http://ws.apache.org/ns/synapse" name="MailProxy"
       transports="mailto"
      statistics="enable"
      trace="enable"
   startOnLoad="true">
 <target>
  <inSequence>
     <property name="senderAddress" expression="get-property('transport', 'From')"/>
     <property name="filename" expression="get-property('transport', 'filename')"/>
     <property name="AttachmentFile"
               expression="stat.csv"
               scope="axis2"
               type="STRING"/>
     <property name="transport.mail.Format"
               value="Attachment"
               scope="axis2"
               type="STRING"/>
     <property name="FORCE_SC_ACCEPTED"
               value="true"
               scope="axis2"
               type="STRING"/>
     <property name="messageType" value="binary/attachment" scope="axis2"/>
     <property name="OUT_ONLY" value="true"/>
     <log level="full">
        <property name="Sender Address" expression="get-property('filename')"/>
     </log>
     <send>
        <endpoint name="endpoint_urn_uuid_A1546EFFD75FC9CCED785986339425964585275">
           <address uri="vfs:file:///home"/>
        </endpoint>
     </send>
     <drop/>
  </inSequence>
  <outSequence>
     <send/>
  </outSequence>
  </target>
  <parameter name="enableMTOM">false</parameter>
  <parameter name="mail.pop3.socketFactory.port">995</parameter>
  <parameter name="transport.mail.ContentType">text/plain</parameter>
  <parameter name="serviceType">proxy</parameter>
  <parameter name="mail.pop3.socketFactory.fallback">false</parameter>
  <parameter name="transport.mail.Address">[email protected]</parameter>
  <parameter name="transport.PollInterval">1</parameter>
  <parameter name="mail.pop3.host">pop.gmail.com</parameter>
  <parameter name="mail.pop3.password">mdp</parameter>
  <parameter name="mail.pop3.user">user</parameter>
  <parameter name="mail.pop3.port">995</parameter>
  <parameter name="transport.mail.Protocol">pop3</parameter>
  <description/>
 </proxy>'
file email wso2 wso2esb vfs
1个回答

0
投票
    I am also working with same requirement in WSO2 EI.here i have downloaded image from email to some local folder successfully, Problem is downloaded image(through coding) is not viewable, but direct download image is viewable by using the same Windows photo Viewer.
   [https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get][1]

   <sequence name="ProcessAttachmentSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
 <log level="custom">
        <property name="===ProcessAttachmentSequence" value=" Called=="/>
 </log>
    <!-- emailmessageId which is already retrieved in some other process in this same project-->
    <property description="GmailMessageId" expression="//htmlProcessEmailBody/emailMessageId/text()" name="emailMsgId" scope="default" type="STRING"/>
    <header expression="fn:concat('Bearer ', $ctx:uri.var.gmail.accessToken)" name="Authorization" scope="transport"/>
  <!--  To get Save Directory  from localentry-->
    <property description="IMAPDetails" expression="get-property('IMAPDetails')" name="IMAPDetails" scope="default" type="OM"/>
     <property description="saveDirectory" expression="$ctx:IMAPDetails//*[local-name()='saveDirectory']/text()" name="saveDirectory" scope="default" type="STRING"/>

    <!-- Loading Gmail Credentials -->
    <sequence description="Load Configurations" key="VBEmail_GmailConfigurations"/>
    <gmail.init>
        <userId>{$ctx:userId}</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>
    <gmail.readMail>
        <id>{$ctx:emailMsgId}</id>
    </gmail.readMail>
    <property description="emailAttachmentId" expression="//parts/filename[text()!='']/../body/attachmentId/text()" name="uri.var.attachmentId" scope="default" type="STRING"/>
    <property description="AttachmentFileName" expression="fn:concat('VB_SellMyCarImage_',substring-after(get-property('operation','messageId'),'urn:uuid:'),'_',get-property('SYSTEM_DATE', 'yyyyMMddHHmmss'),'.jpg')" name="AttachmentFileName" scope="default" type="STRING"/>
    <header expression="fn:concat('Bearer ', $ctx:uri.var.gmail.accessToken)" name="Authorization" scope="transport"/>
    <call>
        <endpoint>
            <http method="get" uri-template="{+uri.var.gmail.apiUrl}/{+uri.var.gmail.apiVersion}/users/{+uri.var.gmail.userId}/messages/{+uri.var.id}/attachments/{+uri.var.attachmentId}"/>
        </endpoint>
    </call>
    <!-- Remove response custom header information -->
    <header action="remove" name="x-li-format" scope="transport"/>
    <header action="remove" name="X-LI-UUID" scope="transport"/>
    <header action="remove" name="X-Li-Pop" scope="transport"/>
    <header action="remove" name="X-Li-Fabric" scope="transport"/>
    <header action="remove" name="x-li-request-id" scope="transport"/>
    <property description="emailAttachment" expression="base64Decode(//data/text(),'ISO-8859-1')" name="emailAttachment" scope="default" type="STRING"/>
    <property description="AttachmentFilePath" expression="fn:concat(get-property('saveDirectory'),get-property('AttachmentFileName'))" name="AttachmentFilePath" scope="default" type="STRING"/>
    <log level="custom">
        <property expression="get-property('saveDirectory')" name="===saveDirectory==="/>
        <property expression="get-property('AttachmentFileName')" name="===AttachmentFileName==="/>
         <property expression="get-property('AttachmentFilePath')" name="===AttachmentFilePath==="/> 
    </log>
     <fileconnector.create>
        <source>{$ctx:AttachmentFilePath}</source>
        <inputContent>{$ctx:emailAttachment}</inputContent>
    </fileconnector.create>
    <fileconnector.isFileExist>
         <source>{$ctx:AttachmentFilePath}</source>
    </fileconnector.isFileExist>
     <log description="Filter then Log" level="custom">
           <property expression="$ctx:AttachmentFilePath" name="===File Path==="/>
           <property expression="json-eval($.fileExist)" name="===File Exist==="/>
     </log>
</sequence>```` 


  [1]: http://Reference%20link
© www.soinside.com 2019 - 2024. All rights reserved.