Midrange News for the IBM i Community


Posted by: ceavers
Looking to Email HTML type forms
has no ratings.
Published: 24 Apr 2012
Revised: 23 Jan 2013 - 1640 days ago
Last viewed on: 20 Jul 2017 (3568 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Looking to Email HTML type forms Published by: ceavers on 24 Apr 2012 view comments(7)

Iím looking for someone to guide me on the correct path, what we are trying to do is email customers order/shipment confirmations in HTML format(company wants email to look pretty).† Iíve seen that easy400.net has a Mime&Mail utility that can send this information.† I guess what Iím looking for, is how RPG write/updates the HTML in IFS or do I need to use JAVA.† Also will need to use logoís and pictures with these emails but thatís not important to me currently.

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Looking to Email HTML type forms
Posted: 5 years 2 months 29 days 7 hours 4 minutes ago

I have the SENDMAIL Java API wrapped up in a library with an install routine. It supports attachments and HTML. It is not a product, but just a tool that I previously gave away at RPG World and other events.

Basically you restore the save file, restore the library and then call the setup/install routine. Then from within RPG you can call the QuickMail or SendMAIL APIs to send HTML based email (specifying the HTML file name from the IFS on the API). Or you can use the SNDEMAIL CL command to do the same thing.

I don't have time today or tomorrow to put it together for a download, but I should be able to put it up on dropbox and then put a link in here soon. If you want it.

What release of IBM i are you running?

Posted by: clbirk
Premium member *
Comment on: Looking to Email HTML type forms
Posted: 5 years 2 months 29 days 5 hours 48 minutes ago

While I use brad stones (www.bvstools.com) mailtool plus to do the emailing, the creation of the document (besides telling the email client it is html/txt) is the important factor.

You may actually want to consider doing a pdf and emailing it instead but to do an html document that has images, you have like two choices, to embed the images into the file (which I hate) or to call them from a website.

That is say you want your logo on the top, what you would do is at your web service that is in the public domain (or you buy a cheap $5 account like at hostgator and make it a subdomain), you put your images. You will want your images to be in a folder that is separate from your main website stuff. What do I mean by that. Lets assume that your website is called www.mywebsite.com and that your logo is in images folder and is called† mylogo7.gif.† Typically you would do an img src command with http://www.mywebsite.com/images/mylogo7.gif† The problem with that is your web site designer comes along and totally revamps your web page, including the size and/or name of the logo, guess what... So what I am recommending is you create a separate folder called images1 or csimages or itimages etc. and you put them in there and they are for your stuff alone.

You will be using tables, etc. Your file you write out will need to have all the html tags, etc. in it. You will want to try it with multiple browsers and versions of browsers to be sure it displays the same. What do I mean by this? I mean you try firefox, ie7, 8 and 9 and probably chrome and something for mac users also.

Now you have to get the info probably into the IFS for sending which will mean that in the simpliest sense you will go and have the program output ONE customer/one invoice per run of the job. It will be written to a flat file, and then you will use cpytostmf command or at least this is one option. Your second option would be to open (create), write and close multiple ifs files in your rpg program. A third way is that you leave your current program alone except you write out a single file with all the customers in it, then you write a simple job that will read until it hits a certain record, writing out each and deleting from the input, go process and loop back until the file is empty.

If it was me, I would write the files in the ifs into a folder appending like the invoice# to the file name or that being the file name, so there are no issues with the mail program.† Of course the file names will be suffixed with .htm (dot htm).† You have the choice that your html document could be either within the email itself or an attachment, that depends on what tool you use.

I can go into alot more detail if this is the sort of information you are after, as we email thousands and thousands of emails a day from the ibmi† (tracking notification, order processing stuff, etc.).

chris

I

Posted by: clbirk
Premium member *
Comment on: Looking to Email HTML type forms
Posted: 5 years 2 months 29 days 5 hours 26 minutes ago

Let me go into a bit more detail so I re-read what you were saying. Say that you want to basically leave the format the same but you want to add your logo.

You would do something like in the file you are writing out (I am replacing < > with () so that the browser here does not get confused.

(html)(body)(pre)

(img src=http://www.mywebsite.com/images_other/mylogo.gif)

Dear Sam:

Your order #123455 was shipped on 12/23/09. It was sent via UPS. To track this package,

either go to www.ups.com and enter tracking 1Z123456666546†

(a href="http://www.ups.com/tracking/tracking.html?trackNums=1Z123456666546†")or click here(/a)†

My widget company

1600 Pennsylvania Ave

Washington, DC† 12345

(/pre)(/body)(/html)

Posted by: clbirk
Premium member *
Comment on: Looking to Email HTML type forms
Posted: 5 years 2 months 29 days 5 hours 12 minutes ago

Here is what you COULD have for sending of that email (your output file needs to be one per). While this example runs in S/36E environment, I think you will get the idea

CPYTOSTMF† +†††††††††††††††††††††††††††††††††††††††††††††††††††††††††††††††††††
†† FROMMBR('/qsys.lib/qs36f.lib/sls350hl.file/sls350hl.mbr') +††††††††††††††††††††††
†† TOSTMF('/trackfiles/sls350?L'51,6'?.htm')† STMFCODPAG(*STDASCII) STMFOPT(*REPLACE)†
†††††††††††††††††††††††††††††††††††††††††††††††††††††††††††††††
MAILTOOL TOADDR(?L'1,50'?) +†††††††††††††††††††††††††††††††††††††††††††††††††††††
†††††††† FROMADDR(shippingdept@mywidget.com) +†††††††††††††††††††††††††††
†††††††† SUBJECT('Shipping and Tracking info on order ?L'51,6'?') MESSAGE(*ATT) +†††††††††††††††††††††††
†††††††† ATTACH('/trackfiles/sls350?L'51,6'?.htm') SENDWITH(*MAILTOOL) +†††††††††††††
†††††††† MAILRTR('192.168.101.100) USERTR(*ONLY) BDYCT('text/html')††††††

In my case I pass the email in the LDA in position 1-50 and the order# in 51-56. This part of the job runs over and over till all are sent.

Let me elaborate on that a bit. I go and create out a simple flat file that would have in it what I need, that is order#, tracking#, email address and customer's name.† I take this file and make it delete capable (you could also update it as "sent") and then in a simple job, I read the first unsent (undeleted) record and format out a file like above in previous post with the html. I go and delete that record, and end the program (i.e. seton LR), I go and do the cpytostmf and mailtool (or whatever tool you use to send), and go back into the program that will read the next one and I repeat that over and over until the simple flat file is empty.

Now with mailtool I believe you could call it within your program and do the send, etc. I just choose to do it pretty simplisticly, plus it gives me a very easy way to test because I can make the to email address instead of being a value out of the lda (in my case), I can stick in my email address. I can run the program and go check all the email. (or change it not to loop, etc.).

The "pre" command does fixed width stuff, depending on how you want it to be you may use. A new line (i.e. carriage return or a new record) will be a new line, where as if you are not "pre" it will break based upon the browser.

With mailtool I can send the file as an attachment or within the body (since I told it *ATT) the first file will be actually in the email.

With mail tool plus I can use whatever smtp server I want, whether it be the i, mailtool itself, a local smtp server or the one I use for all my email clients, etc.

So I hope this gives you an idea. I am sure I will be "criticized" for the simplistic approach, but it works.

Posted by: clbirk
Premium member *
Comment on: Looking to Email HTML type forms
Posted: 5 years 2 months 29 days 4 hours 43 minutes ago

One more comment then I will shut up.

I talked about how I wrote out a phsyical file and then I went and processed the email out of it, one record at a time. I put all the formatting of the email in that so that if I needed to reword the email, etc. I was playing in a simple program, not something more complex.

There are several ways to send the email, one being using what you saw probably over at easy400, bob's tool, mailtool. There is another way you can do all this.

You can create a single file that all your email records are in, and at the end of each email set, put in a record like ^^^john@doe.com† (the email address to send to).

Then you can ftp this to a pc and write a quick vb dot net or c# dot net program that will break this down into dozens or hundreds of files into a folder and then use a product like gammadyne mailer to mail it out OR use the vb.net program to actually email each. That would mean that you would have to do like an strpco and strpccmd (or aaron bartell's rpg2desktop) to trigger the pc side of things.

Long ago we used to have thousands of daily tracking to send, all at the end of the day, the i (at that time as/400) created a single file (actually 2, the single file with them all and a simple csv file OR a single csv file that you do parameter subs in gammadyne) and we then let gammadyne mailer send them out. Since getting mailtool we now send them from the i side of things.

In what I decribe here there is no need for the ifs.††I simply wanted to give you an alternative method. For example with tieing in gammadyne mailer on the pc side of things, it could be as simple as:

"order","date","tracking number","howship","emailaddress"

"123456","12/15/12","1Z33333333333","UPS","john@doe.com"

"43434","12/15/12","34343434343","FEDX",jim@doe.com

etc.† and in gammy you can make compares so that you give different hyperlinks if it is ups or fed ex, etc.

I think gammadyne mailer on the pc side of things is the greatest tool there is. I have probably sent upwards of 250 million or more emails with it.

Posted by: dzarder
Premium member *
Port Washington, WI
Comment on: Looking to Email HTML type forms
Posted: 5 years 2 months 26 days 6 hours 18 minutes ago

For what it is worth, PHP can send HTML formatted e-mails very easily.† Any chance you have Zend Server loaded on your system?

Posted by: clbirk
Premium member *
Comment on: Looking to Email HTML type forms
Posted: 5 years 2 months 25 days 6 hours 57 minutes ago

That is very true, you would simply have to have a table with the pertinent information in, and access that db2 table from php, but you still have to format the "html", and you then would simply go and let it send them. The alternative would be that you would create a table that had say 3 columns, some unique id, the whole text of the email (html formatted) and a column to update when it was sent (maybe a date/time stamp) (yes one could delete the row from the table).

The table could be either db2 because php does a wonderful job of reading db2 files or it could be mysql (now zend dbi)†which if you had it set with the db2 engine could be read by your php and RPG programs.

You would have to decide on the "email stmp server" which off the top of my head, I forget how one configures what you use. I used to read comments like stay away from the i's stmp server (and so I did).

I put a small smtp server on the lan, because the last thing you want is for "mail to fail" because of some glitch where the i can't contact the remote smtp server.† What I do, is I have actually a windows xp pc (an old one), with a product called mailenable (a great email server software) with their standard version which is FREE and it acts as a relay taking the emails from the i (and actually other sources within the lan) and then forwards them to the real smtp server (or it can deliver them depending on your preference).† Seldom do you have an issue connecting to a device on your lan compared to a "remote" device.

You see, even if the remote one is down, or some glitch, the "internal smtp server" will hold the mail until it can connect with the remote one. So think of it as a holding buffer.

Yes php is another alternative that we have but you still have to think in terms of an html stream, where to put your images, how you might hyperlink, etc.

chris