Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
dragomir_anachkov
Product and Topic Expert
Product and Topic Expert

Introduction






In this blog, we'll take a look at one of the newest Eclipse Dirigible features. It allows you to send e-mails from Eclipse Dirigible with the Mail Client API.

For the purpose of this demo, I'll be using my Eclipse Dirigible (SAP Ephemeral edition) setup in the Neo environment of SAP Cloud Platform along with a Gmail account used for testing this use case. I've also assigned the Operator and Developer roles to my user in advance. For more information about this setup process, see Eclipse Dirigible - Setup on SAP Cloud Platform.

Summary






This is a fairly straightforward scenario once you have deployed Eclipse Dirigible as a Java application in the SAP Cloud Platform cockpit. It's also worth pointing out that the mail server configuration is kept in a destination in the cockpit. This destination contains properties for the mail server and the Mail Client API. The full set of mail properties is available here.

Try It Out






Assuming that you've already set up Eclipse Dirigible and the Java application is started, let's have a look at the next steps:

1. First, navigate to your subaccount in the SAP Cloud Platform cockpit and go to Applications → Java Applications.

2. Open the Overview page of the Eclipse Dirigible Java application:



3. Go to Configuration → Destinations.

4. Create a New Destination with the following properties:
Name: gmail
User: your Gmail username
Password: your Gmail password

Also, choose New Property to add these mail.* properties:
mail.transport.protocol: smtps
mail.smtps.host: smtp.gmail.com
mail.smtps.port: 465
mail.smtps.auth: true

5. Save the new destination.



6. Go back to the Overview page of your Java application in the cockpit and open the Eclipse Dirigible Web IDE.

7. Create a project and a JavaScript service in that project.

TIP: Here's what a sample .js file may look like:



This .js file is based on the following JavaScript template:
var response = require("http/v4/response");
var destinations = require("core/v4/destinations");
var mail = require("mail/v4/client");
var destination = destinations.get("gmail");
var mailClient = mail.getClient(destination);
var from = "<your-gmail-account>@gmail.com";
var recipients = {
to: ["<your-gmail-account>@gmail.com", "<another-gmail-account>@gmail.com"],
cc: "<another-email-account>",
bcc: "<another-email-account>"
};
var subject = "Hello World";
var text = "<h1>Hello World</h1><br><img src='https://miro.medium.com/max/3200/1*0KFB17_NGTPB0XWyc4BSgQ.jpeg'></img>";
var subType = "html";
mailClient.send(from, recipients, subject, text, subType);
response.println("Mail Sent");

You can use this template to test it out yourself.

8. Publish your project. To send an e-mail, refresh the URL in the Preview tab.

TIP: Since Google's Gmail SMTP server is being used, you'll have to make some adjustment to your Google security settings. You'll have to turn on the "Less secure app access" so that this e-mail can go through to your inbox:



9. Go to your Gmail inbox and...



... voila! The e-mail has arrived.

Conclusion






This scenario is not restricted to Gmail only. You can always configure another mail server in the destination by using the following mail properties, or even by providing environment variables in Dirigible itself.

If you have any questions, please leave a comment below.

Related Information:


Managing Documents with Eclipse Dirigible in the SAP Cloud Platform Neo Environment
6 Comments