Page 1 of 1

Email with Attachment

Posted: Tue Mar 27, 2018 2:31 am
by lawingo
I hope this is an easy solution.

I want to send an email with attachment from the iSeries:

Here's what I have

Code: Select all

#EMAILTO := 'lawingo@sherrillfurniture.com'
#EMAILFROM := 'SMTP:lawingo@sherrillfurniture.com'
#EMAILSBJ := 'Test Report'
#EMAILMSG := 'tEST rEPORT'
#EMAILRTNM := '/emaildocs/CHAD.PDF'
It passes these above parameters to this function that runs on the iSeries:

Code: Select all

Use Builtin(MAIL_START) To_Get(#FW_RETCD)
Use Builtin(MAIL_SET_SUBJECT) With_Args(#EMAILSBJ) To_Get(#FW_RETCD)
Use Builtin(MAIL_ADD_ORIGINATOR) With_Args(#EMAILFROM) To_Get(#FW_RETCD)
Use Builtin(MAIL_ADD_RECIPIENT) With_Args(TO #EMAILTO) To_Get(#FW_RETCD)
Use Builtin(MAIL_ADD_TEXT) With_Args(#EMAILMSG) To_Get(#FW_RETCD)
If Cond(#EMAILRTNM <> ' ')
Use Builtin(MAIL_ADD_ATTACHMENT) With_Args(#EMAILRTNM)

Endif

Use Builtin(MAIL_SEND) To_Get(#FW_RETCD)
My problem is this: The field #EMAILRTNM is the file location & name of the report I want to attach to my email. The location I have in the above code is an IFS directory. The email sends but without the attachment. What am I doing wrong?

Best,
Chad

Re: Email with Attachment

Posted: Tue Mar 27, 2018 4:22 am
by atostaine
Is there anything in the joblog?

Does DSPLNK ''/emaildocs/CHAD.PDF' work from a 5250 session?

Re: Email with Attachment

Posted: Tue Mar 27, 2018 4:38 am
by lawingo
Job Log says "E-Mail message sent". It sends the email correctly - but without the attachment. Apparently after you execute the "MAIL_START" command if any of the following commands error out you have to re-issue the "MAIL_START" before executing the "MAIL_SEND" command otherwise it fails. I found that out in testing <grin>.

Yes I can do a DSPLNK ''/emaildocs/CHAD.PDF' from a 5250 session.

Re: Email with Attachment

Posted: Tue Mar 27, 2018 4:51 am
by atostaine
You can turn on the email journals and review those.

Turn on journaling for SMTP

CHGSMTPA JOURNAL(*YES), restart SMTP

View the journals
http://www-01.ibm.com/support/docview.w ... s8N1012063

Re: Email with Attachment

Posted: Tue Mar 27, 2018 7:38 am
by lawingo
Right or Wrong - Here is my working solution. I canned the Lansa Mail BIF (I got the attachment to work but it would send as garbage - I think there was some encoding issues) that I had previously put and I found this nifty utility on the iSeries called "SNDSMTPEMM" http://www-01.ibm.com/support/docview.w ... s8N1011153. I take my input parameters for To, From, Subject, Attachments, etc.. and I build a string.

Code: Select all

#W_CMD := 'SNDSMTPEMM RCP((' + #EMAILTO + ') (' + #EMAILFROM + ' *CC)) SUBJECT(' + "'" + #emailsbj + "'" + ') NOTE(' + "'" + #emailmsg + "'" + ') ATTACH((' + "'" + #EMAILRTNM + "'" + ' *PDF))'
#EMAILFROM is just a copy of the email to the person who sent the thing. Make sure you have the Subject & Note in Quotations.

I then execute a "EXEC_OS400" command with the built string.

One tidbit for anyone who wants to use this approach is to make sure you have the AS400 user who will be sending the email in the System Alias Table >> GO TCPADM > #2 'Configure TCP/IP applications' > #12 'Configure SMTP' > #1 'Work with system alias table'

Again - this is good for emailing any document from the iSeries IFS.

Re: Email with Attachment

Posted: Tue Mar 27, 2018 8:05 am
by TomC
I have recently used this BIF successfully. I seem to remember having an issue with the attachment, and adding the second argument (the attachment name) resolved the issue. I could be wrong, but my RDMLX looks like the following:

#std_textL := '/lansa_dcxpgmlib/jsm/instance/Order_' + #FOHMEM.AsString + '.pdf'
Use Builtin(MAIL_ADD_ATTACHMENT) With_Args(#std_textL 'OrderConfirmation.Pdf') To_Get(#LEM_RETC)