In my other post, I explained “How to send custom email from SAP Hybris” using the Hybris approach and a good practice approach to it. While the other way of sending an email from Hybris is the standard, it is time consuming and not very beginner-friendly.

In this post, I will be explaining how to send an email the shorter way, through Java, using Apache Commons mail that is included in the Hybris platform. For more documentation on Commons Email from apache, click here.

This post will explain how to send a regular email, without any attachments. The following code snippet is responsible for sending an email out with Java only in Hybris:

try {

    final Email email = MailUtils.getPreConfiguredEmail(); 
    email.setCharset("UTF-8");
    email.setSubject("Email's subject");
    email.addTo("to@foobar.com");
    email.setFrom(john@doe.com);
    email.setMsg("This is the message (body) of the email!");
    email.send(); // send the email

} catch (final EmailException e) {
    LOG.error("Error sending an email", e);
}

Compare to how the standard is, this is an easy quick approach to send an email out. We should only use this approach if the email being sent wouldn’t require a lot of customizations or beautifications as it cannot be customized or styled as much.

Finally, if there are any other ways that we can send out an email in Hybris, do let me know in comments. Thank you!

Categories: Hybris

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *