easily send email directly from rpg! - mowyourlawn learn how to easily send email from your iseries...

24
RPGMail Easily send email directly from RPG! by Aaron Bartell Krengel Technology Inc. [email protected] Copyright Aaron Bartell 2011

Upload: buianh

Post on 08-May-2018

276 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

RPGMailEasily send email directly from RPG!

by Aaron BartellKrengel Technology [email protected] Aaron Bartell 2011

Page 2: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Joke Of The DayFound in employee handbook…SURGERY:Operations are now banned. As long as you

are an employee here, you need all your organs. You should not consider removing anything. We hired you intact. To have something removed constitutes a breach of employment.

Page 3: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

AbstractLearn how to easily send email from your iSeries using

open source software RPGMail. Make your boss happy and take this code home to gain immediate RPG Summit ROI. Not only will you have a free utility (RPGMail) to put on your iSeries after leaving this session but you will also get a full understanding of how the guts work in conjunction with Sun's JavaMail API's to send email directly to your mail server (i.e. Microsoft Exchange), completely by-passing the problematic iSeries MSF (Mail Server Framework). Don't miss this one!

Page 4: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

• Inception: 2002-11-03• Free and Open SourceTools

– RPGMail 3352 downloads since 2006-06-01

– RPG Chart Engine 1248 downloads since 2006-10-10

– RPG To Desktop 768 downloads since 2007-11-07

– System i SVN Client(source control)‏ 342 downloads since 2008-02-21

MowYourLawn.com

Page 5: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Email Addiction

“Dear Andy: How have you been?Your mother and I are fine. We miss you. Please sign off your computer and come downstairs for something to eat. Love, Dad.”

Page 6: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

RPGMail – What,Why,How?• What: A set of RPG sub procedures (say service program) that

utilize the JavaMail API's from Sun to send emails with ease from your iSeries RPG program without limitations on the amount of email addresses or attachments.

• Why: IBM’s MSF (Mail Server Framework) is/was problematic in that it just stopped working with a whole bunch of emails queued and waiting to be sent out. One approach to “fixing” this problem was to clear/restart the MSF.

• How: I took my first Java class at the local technical college and developed RPGMail shortly after. After learning how to use Eclipse and reading different tutorials on JavaMail, I waded my way through the creation of a Java wrapper to JavaMail to simplify the use at that level. I then added an RPG wrapper to make it easy to use for other RPG developers in my shop.

Page 7: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Requirements• OS/400 V5R1• RPG Compiler (to recompile example programs with your info)‏• 5722JV1 *COMPATIBLE Java Developer Kit 1.4• You need to have access to your own SMTP server (i.e. Microsoft

Exchange).• At least a small sense of adventure! You are, after all, using Java!

Page 8: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Installation1. Unzip the downloaded file to c:\temp (or the directory of your choice).

2. Issue the AS/400 command: CRTSAVF FILE(QGPL/RPGMAIL) AUT(*ALL)‏

3. FTP the file RPGMAIL.SAVF from your PC to the AS/400 in BINARY mode into the save file RPGMAIL in library QGPL.

4. Issue the AS/400 commands.

CRTLIB LIB(RPGMAIL)‏

RSTOBJ OBJ(*ALL) SAVLIB(RPGMAIL) DEV(*SAVF) SAVF(QGPL/RPGMAIL)‏

CPYTOIMPF FROMFILE(RPGMAIL/QSOURCE MYTEXTFILE) TOSTMF('/home/mytextfile.txt') MBROPT(*REPLACE)‏

STMFCODPAG(*PCASCII) RCDDLM(*CRLF) DTAFMT(*FIXED)‏

ADDLIBLE RPGMAIL

5. Copy the *.jar files included with the download to IFS folder /java/. Use a Windows drive mapping, FTP, or WDSC RSE to do this.

6. Change source members T1_RPGMAIL and T2_RPGMAIL in RPGMAIL/QSOURCE to have valid email addresses

and SMTP host/port, and then recompile and run.

Page 9: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Uses For RPGMail

1. Send notification emails upon receiving an order.2. Notify customer of order getting shipped and include

carrier and tracking number.3. Send emails to programming staff if critical

processes don’t complete.4. Send out emails to existing customers about

discounts and specials you may be having (i.e. mass emailing). Be careful with this because of “spam laws” and getting your IP address on “black lists”.

5. Email reports that have been created on the iSeries.

Page 10: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Sending Basic EmailH spec thread(*serialize) is necessary in Java situations.

Page 11: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Email Attachments and File as Body

Page 12: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Prime the Java environment. Note that this only needs to be called once per job. Calling it again will simply have no affect.

What is a CLASSPATH you ask? Very similar to a library list.

RPG Guts

Page 13: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Create/Instantiate the RPGMail.class Java object for later use in our RPG code.

RPG Guts contd…

Page 14: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

This shows how most of the remaining API’s work. They receive in the RPGMail.class object instance, along with other parameters, and turn around to call the corresponding Java prototype.

RPG Guts contd…

Page 15: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

RPGMail_send is the only API that receives information back from the Java class. A Java object of type java.lang.String is returned from RPGMail.class. If the process was successful the String will be empty, otherwise it will be occupied with an error (most likely occupied with what’s called a stack trace). This was put in place because when errors occur in Java they aren’t recorded in an extended fashion within the OS/400 job log.

RPG Guts contd…

Page 16: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Java GutsExample Java program that shows how to make use of the RPGMail.class object. The JavaMail API

by itself wasn’t able to be quickly implemented in other Java programs so an additional Java wrapper (RPGMail.java) was added to wrap up the ugliness. Look similar to the RPG example?

Page 17: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Java Guts contd…Here are three Java methods from RPGMail.java, showing what the Java wrapper looks like.

Page 18: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Java Jump-start for RPG'ersI wrote an article for IBMSystemsMag.com that guides you

through the general concepts of modifying RPGMail as if you were a complete noob to the process. You can see the article by going to www.IBMSystemsMag.com. In the search box on site you can enter my name and you should find the article. The article is titled “Roll The Tape – A Java Jump-start video tutorial for RPG'ers”.

Or you can view the digital version of the magazine by going to the following URL:

http://www.ibmsystemsmagpowersystemsibmidigital.com

Page 19: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Future Enhancements• Email address validation.• Check to see if attachments exists on RPG

end before attempting to send.• High Priority emails.• Encryption??• Authenticate to remote SMTP server• Modify infrastructure to have RPG layer talk

to data queues with Java on the other side. Make process a lot faster and wouldn’t have ANY Java in the RPG source code.

• Anybody want to help?!

Page 20: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

TroubleshootingProblemMessage . . . . : Java exception received when calling Java method.

Cause . . . . . : RPG procedure RPGMAIL_SE in program RPGMAIL/RPGMAILSV

received Java exception "java.lang.NoSuchMethodError: append(Ljava/lang/StringBuffer;)Ljava/lang/StringBuffer;" when calling method"send" with signature "()V" in class "com.mowyourlawn.rpgmail.RPGMail".

SolutionThis means that a previous JDK is being chosen to run the code (most likely

JDK 1.3) and you need to tell the iSeries that you instead want to use JDK1.4. To do this you need to create the following file in the IFS: /QIBM/UserData/Java400/SystemDefault.properties

Once it has been created, open it and place the following line of text in it:java.version=1.4

Save the file and exit. Sign off and back on again. Re-run your RPGMail program.

Page 21: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Troubleshooting contd…• Are other Java applications installed on your iSeries? May be that

their .jar files are loaded into the “shared” Java directory: /qibm/userdata/java400/ext and causing conflicts with your .jar files.

• Make sure the mail/smtp server allows relaying from your iSeries’ IP address.

• You can only start one JVM per OS/400 job and once started you cannot modify the CLASSPATH (among other startup variables). This could pose a problem if you have other Java processes that run BEFORE RPGMail and then RPGMail will be unable to add the necessary .jar files to the CLASSPATH.

• Make sure all your DNS stuff is setup correctly on both the iSeries and network devices.

• Don’t use IFS QDLS for attachments or email bodies.

Page 22: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Other Open Source Java Utilities

Try one of these guys out for yourself to see what you can do!http://sourceforge.net/projects/jfreechart/ (Graphical charts) http://jakarta.apache.org/poi/ (Excel Spreadsheets) http://www.lowagie.com/iText/ (PDF creation) http://www.eclipse.org/birt (Reports) (check out http://www.opensource4iseries.com/ for a

start to this project)‏http://www.pentaho.com/products/reporting/ (Reporting)‏

Page 23: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Other Open Source Siteshttp://www.opensource4iseries.com/

http://iseries-toolkit.sourceforge.net/

http://www.softlanding.com/websphere/rse.htm

http://www.scottklement.com/oss.html

http://www.martinvt.com/Code_Samples/code_samples.html

http://Netshare400.com

http://www.think400.dk/downloads.htm/

http://home.alltel.net/craigru/jcrcmd2.html

http://sourceforge.net/projects/iseriestoexcel

http://www.rpgiv.com/downloads/

http://www.code400.com

Page 24: Easily send email directly from RPG! - MowYourLawn Learn how to easily send email from your iSeries using open source software RPGMail.Make your boss happy and take this code home

Aaron Bartell [email protected] developer of RPG-XML Suite (www.rpg-xml.com)‏

and owner of www.MowYourLawn.com and check out his latest effort at www.SoftwareSavesLives.com

We have reached the end!

.com/aaronbartell