How to get email content/body using Katalon?


I’m looking for a way to get the content/body of a mail using Katalon. I’ve tried using the Gmail plugin which is available in the store but it looks like it needs an update (couldn’t get it to work properly due to several errors).

Is it even possible to use Gmail in this case (as they seem to have a strict privacy policy now)?

I’d appreciate any help.

Thanks in advance.

You can import and use the JavaMail package. I have tested it out enough to know it will work for us when we get to the point of needing it:

Though you will need to go in to the security settings for the account and allow ‘Less secure app access’, otherwise any calls to authenticate will be blocked.

Thank you, I’ll give that a try!

1 Like

Here you go, give this a try.

Obviously use your own mailbox username/pw combo: copy the text and dump it into your own keywords package/class etc.

The getLastReceivedEmailBody function has a folder.getMessages() call. That returns them in reverse order of when they were received, so newest is last.

JavaMail.txt (7.7 KB)

1 Like

Thank you! this seems to be working much better than the plugin I tried before.

1 Like

Hello again,

it’s working perfectly fine with one exception: If I try to get the newest mail body, it doesn’t return the text for some reason.

This is how the code looks after I added the “newest email” part:

If I use getContent().toString on foundMessages[foundMessages.length-1] it returns the HTML code of my email but it doesn’t seem to work with your getTextFromMessage() function. Maybe I missed something here.


That is interesting. I just tried it again here and it does work OK.

Thinking it could be something to do with the format of the email perhaps…

I can’t look in to it any deeper right now due to other work stuff but will try and have a look over the weekend.


no worries, take your time. I believe you may be right. I tried it with a different mailbox and it worked fine. I’ll post here if I find a solution.

I managed to solve my problem by basically converting the HTML mail into text. Thanks again for your help.

1 Like

Hi, glad you worked it out.

I expect I will need it to work with HTML for our project so will post back here when I have it sorted.

1 Like