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
Johnny_B_
Active Participant
Hi Dragomir,

Thank you for this blog and also your other contributions! We have a number of Apps to develop as extensions for an S/4HANA Cloud Essentials tenant. Now I have to choose the right environment.

One of the options is tu use Dirigible (on NEO or CF?)  but of course Java node.js etc. are also possible.

What kind of puts me off from dirigible is that I do not know how much it is used, will it continue to improve, or will it just slowly fade away like som other open source projects.

What is your opinion?

Johannes
dragomir_anachkov
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Johannes,

I can't say if Eclipse Dirigible is the best solution to your business case, but I can give you some of my personal insights and my overall opinion about Dirigible. I’m biased so please keep that in mind.

I can say for sure that it's an active open-source project. It's been around for the last 5 years, and I've been actively contributing to the project since 2016.

Since its conception, Dirigible has had several major releases: Eclipse Dirigible 1.x, 2.x, 3.x, and the latest major version 4.x with the latest release 4.3 from last week (11.03.2020). You can check all releases at https://download.eclipse.org/dirigible/. In addition to all these major version upgrades, there have been many improvements in the architecture, the underlying technologies, and the supported scenarios.

For example, Dirigible started "only" with in-system development experience, a few runtime artifacts (*.table, *.view), and a basic Web IDE. Now, it features low-code/no-code development, modeling and generation, support for mobile and cloud-native applications, in-app extensibility and extensions to the Dirigible Web IDE among others.

Ideas and pull requests for new features have always been very much appreciated. We also welcome all bugs reported by the open-source community and we do our best to address them in a reasonably timely manner: https://github.com/eclipse/dirigible/issues

Feel free to monitor the activity of the main repository here: https://github.com/eclipse/dirigible/graphs/contributors. Also, you can follow the separate DirigibleLabs organization for all kinds of projects, demos, clients, and modules related to Dirigible at https://github.com/dirigiblelabs.

There are also two new recent blogs on how to deploy Dirigible in the SAP Cloud Platform Neo and Cloud Foundry environments:

Last but not least, Dirigible is open-sourced under the Eclipse Public License v1.0 (EPL v1.0), meaning that you can fork, reuse, and rebrand it as you wish at any time. For more information, see https://www.dirigible.io/help/license.html.

So all in all, I can safely say that Eclipse Dirigible keeps growing and there are no signs of slowing down in the foreseeable future.

I hope this helps! If you have any other questions, feel free to share them.

Best regards,

Dragomir
former_member674806
Discoverer
0 Kudos
Hi Dragomir,

 

I have followed the instructions and the current version of my Dirigible is v5.0. But unfortunately I encounter an error on this line. It seems its not accessing the function on mail/v4/client.
var mailClient = mail.getClient(destination);

see attached for exact error.

 

Regards

Morris
former_member674806
Discoverer
0 Kudos


error message

dragomir_anachkov
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Morris,

Thanks for the feedback. First, make sure you've published the project in the IDE and after that refresh the preview:


If that doesn't work, can you check the logs in the cockpit for any other errors or exceptions? Also, in which SAP Cloud Platform environment are you trying to run the scenario - Neo or Cloud Foundry?

Best regards,

Dragomir
0 Kudos
Hi morriscastillo

 

You can reach us at dirigible-dev@eclipse.org, so we could provide you with better assistance and we could invite you to the community Slack channel for better collaboration as well.

Are you using the SAP package of Dirigible (ROOT.war)? Also can you share the log file (“ljs_trace.log”)? Does the sample work without using a destination, but with hard-coding the values?

 

Regards,

Yordan