0

我有一个 SAP CAP Nodejs 应用程序,我正在尝试使用sap-cf-mailer包从 CAP 应用程序发送电子邮件。

如示例中所述,我在 BTP 中创建了一个目标服务,当我尝试将应用程序部署到 BTP 时它失败了。

当我使用本地运行应用程序时cds watch,它会出现以下错误

VError:没有服务匹配目的地

这是我的 mta.yaml

## Generated mta.yaml based on template version 0.4.0
## appName = CapTest
## language=nodejs; multitenant=false
## approuter=
_schema-version: '3.1'
ID: CapTest
version: 1.0.0
description: "A simple CAP project."
parameters:
  enable-parallel-deployments: true
   
build-parameters:
  before-all:
   - builder: custom
     commands:
      - npm install --production
      - npx -p @sap/cds-dk cds build --production

modules:
 # --------------------- SERVER MODULE ------------------------
 - name: CapTest-srv
 # ------------------------------------------------------------
   type: nodejs
   path: gen/srv
   parameters:
     buildpack: nodejs_buildpack
   requires:
    # Resources extracted from CAP configuration
    - name: CapTest-db
    - name: captest-destination-srv
   provides:
    - name: srv-api      # required by consumers of CAP services (e.g. approuter)
      properties:
        srv-url: ${default-url}
    
     
 # -------------------- SIDECAR MODULE ------------------------
 - name: CapTest-db-deployer
 # ------------------------------------------------------------
   type: hdb
   path: gen/db  
   parameters:
     buildpack: nodejs_buildpack
   requires:
    # 'hana' and 'xsuaa' resources extracted from CAP configuration
    - name: CapTest-db


resources:
 # services extracted from CAP configuration
 # 'service-plan' can be configured via 'cds.requires.<name>.vcap.plan'
# ------------------------------------------------------------
 - name: CapTest-db
# ------------------------------------------------------------
   type: com.sap.xs.hdi-container
   parameters:
     service: hana  # or 'hanatrial' on trial landscapes
     service-plan: hdi-shared
   properties:
     hdi-service-name: ${service-name}

 - name: captest-destination-srv
   type: org.cloudfoundry.existing-service

这是CDS服务的js文件

const cds = require('@sap/cds')

const SapCfMailer = require('sap-cf-mailer').default;
const transporter = new SapCfMailer("MAILTRAP");

module.exports = cds.service.impl(function () {

    this.on('sendmail', sendmail);
});


async function sendmail(req) {
    try {
        const result = await transporter.sendMail({
            to: 'someoneimportant@sap.com',
            subject: `This is the mail subject`,
            text: `body of the email`
        });
        return JSON.stringify(result);
    }
    catch{

    }
};

我正在关注以下示例

从 nodejs 应用程序发送电子邮件

将电子邮件集成到 CAP 应用程序

4

1 回答 1

0

您是否创建了您的默认-.. json 文件?它们需要连接到 BTP 租户上的远程服务。您可以在这样的 SAP 博客上找到更多信息: https ://blogs.sap.com/2020/04/03/sap-application-router/

您还可以使用 sap-cf-localenv 命令: https ://github.com/jowavp/sap-cf-localenv

这个工具是实验性的,据我所知,这只适用于 CF CLI V6。更高版本正在以另一种格式获取服务密钥,这导致命令失败。

亲切的问候,托马斯

于 2022-01-12T13:59:55.037 回答