HACP & HATS User Group

HACP & HATS User Group

HACP & HATS User Group

This group is dedicated to share news, knowledge and insights about HACP (Host On-Demand and Personal Communications) & HATS products

 View Only

Sending E-Mails from the application in HATS

By Shobith R posted Mon October 31, 2022 09:18 AM

  

With IBM HATS, you can create Web applications and Rich client applications that provide an easy-to-use graphical user interface (GUI) for your 3270/5250 applications.

IBM HATS makes it possible to build an application that can scrape data from the host, format it as required, and present the formatted data on an e-mail, programmed to trigger the e-mail automatically on any user action.

To achieve this, the user needs an SMTP server, like Gmail(smtp.gmail.com), Microsoft Outlook(smtp-mail.outlook.com), Yahoo(smtp.mail.yahoo.com), etc.

Let us consider the below HOST screen having a credit report.

                       Figure 1: Transformed screen in IBM HATS displaying a credit report.

First, the user needs to create an IBM HATS macro that extracts the data from the Host screen, for example:

                                                    Figure 2: Example Macro extract action.

 And then convert the extract into a JSON Array like this:

                    Figure 3: Example converted JSON Array.

Next, the user can trigger e-mails with the help of popular libraries like Spring Mail.

Below are a few ways to present the host data in the e-mail.

  1. Using the code below, the user can format it and embed it directly into the e-mail body, as shown in figure 4.
@Autowired
private JavaMailSenderImpl mailSender; 
    
public void sendMail(String from, String[] to, String[] cc, String subject, String msg) throws MessagingException {  
        //creating mail
        MimeMessage message = this.mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setFrom(from);
        helper.setCc(cc);
        helper.setTo(to);  
        helper.setSubject(subject);  
        helper.setText(msg, true);  
        //sending mail
        mailSender.send(message);     
}  

                                       Figure 4: Illustration of the e-mail with the embedded extract.

2. Using the below code, the user can format it as a pdf/jpeg/png/etc. and add it as an attachment to the e-mail as shown in figure 5 (in the example, it is formatted as a pdf).
@Autowired
private JavaMailSenderImpl mailSender; 
    
public void sendMail(String from, String[] to, String[] cc, String subject, String msg, InputStreamSource file) throws MessagingException {  
        //creating mail
        MimeMessage message = this.mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setFrom(from);
        helper.setCc(cc);
        helper.setTo(to);  
        helper.setSubject(subject);  
        helper.setText(msg, true);  
        helper.addAttachment("Credit Report", file); // Adding attachment
        //sending mail  
        mailSender.send(message);     
}

                    Figure 5: Illustration of the e-mail with the extract added as an attachment.

 

The example pdf looks something like this:

                                                       Figure 6: Extract PDF.



Contact us

For further information on Automation, Services offerings, or technical details in IBM HATS/HACP, please write to: ZIO@hcl.com.

 





 

0 comments
11 views

Permalink