0

I have a SAP CAP Nodejs application and I'm trying to send emails from the CAP application using sap-cf-mailer package.

I've created a destination service in the BTP as mentioned in the sample and when I'm trying to deploy the application to BTP it failed.

When I run the application locally using cds watch, it gives following error

VError: No service matches destination

This is my 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

This is the js file of the CDS service

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{

    }
};

I'm following below samples for this

Send an email from a nodejs app

Integrate email to CAP application

tarzanbappa
  • 4,930
  • 22
  • 75
  • 117

1 Answers1

1

Did you create your default-.. json files? They are required to connect to remote services on your BTP tenant. You can find more info about this on SAP blogs like this one: https://blogs.sap.com/2020/04/03/sap-application-router/

You could also use the sap-cf-localenv command: https://github.com/jowavp/sap-cf-localenv

This tool is experimental,a s far as I know, this only works for the CF CLI V6. Higher version are fetching the service keys in another format, which leads to the command to fail.

Kind regards, Thomas