In ongoing integration project we had to add e-mail notification (by Zawinski's law). For development, we are using well known Apache James Server. Setting it up was piece of cake but for initial testing it is good to test send and receive functionality. That can be done in numerous ways, one is to use Groovy. Because we use Java to send e-mail, using Groovy for testing, makes perfectly sense.
To send e-mail one can make use of ant task for sending mail from Groovy. Script is straight forward and inspired by this ONJava article. There is one caveat though, one must load javax.mail library via systemClassLoader.
Putting it all together it looks like self explanatory script below:
To read e-mail, Groovy can also be handy, but script is not one-liner as one above. It is actually rewrite of some Java class found on internet. Use both scripts as you like.
RSARTE 10.x 2017.43
7 years ago
No comments:
Post a Comment