OS2 World Community Forum

OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: Per E. Johannessen on May 03, 2019, 04:07:06 pm

Title: Rexx Socket / SMTP
Post by: Per E. Johannessen on May 03, 2019, 04:07:06 pm
Hi,

I'd like to automate sending e-mails with a file attached from an application I've created with VX-Rexx.  Since I have no experience using Rexx Sockets I'd appreciate help/ sample of how to:
Initialize sockets
Log-in to smtp server
Attach file
Send message
Title: Re: Rexx Socket / SMTP
Post by: Doug Bissett on May 03, 2019, 04:25:57 pm
PMMail has the PMMSEND utility to do things like that.
Title: Re: Rexx Socket / SMTP
Post by: Pete on May 03, 2019, 05:01:45 pm
Hi Per

No idea myself - but if I need to know I would start looking in Rexx Tips and Tricks Version 3.60 which informs me there are/were various libraries available to help with connectivity.

Maybe this rxsock INF file will be of help http://hobbes.nmsu.edu/download/pub/os2/dev/rexx/rxsock.zip


Regards

Pete
Title: Re: Rexx Socket / SMTP
Post by: Andreas Schnellbacher on May 03, 2019, 05:39:17 pm
You can also look at how Marcus de Geus did that in RexxMail. IIRC, attachments have to be base64-encoded, but I don't know how they are appended to the message text.

It looks like a lot of work, so using PMMail or one of the older Mozilla add-ons might be easier.
Title: Re: Rexx Socket / SMTP
Post by: Bogdan on May 03, 2019, 06:23:03 pm
IIRC, attachments have to be base64-encoded,[
Quote
Not true, even for old-school SMTP.

Quote
but I don't know how they are appended to the message text.
Please take a look at MIME.

RXHELO which utilises RXSOCK is a good starting point, but nowadays authentication features should be considered unless you're running an MTA for in-house operations.
Title: Re: Rexx Socket / SMTP
Post by: Per E. Johannessen on May 03, 2019, 08:32:42 pm
For now I think I'll go for the PMMSEND utility.

Still, I'd like to learn how do it with RxSock.

"RXHELO which utilises RXSOCK is a good starting point"

Is RXHELO a library?
Or do you mean RXHELO as a term for the connection/authentication commands between the client and the smtp server?

Found somewhere a link to rxhelo.cmd, but unfortunately the link was not available anymore.
Title: Re: Rexx Socket / SMTP
Post by: Andreas Schnellbacher on May 03, 2019, 09:47:11 pm
I've found another example written in REXX: John Small's ReleaseTool.cmd of FM/2. See the fm2/trunk source directory. It's much shorter than RexxMail.cmd, but regarding emails, it's only able to send them.
Title: Re: Rexx Socket / SMTP
Post by: Tom on May 03, 2019, 11:10:42 pm
Found somewhere a link to rxhelo.cmd, but unfortunately the link was not available anymore.

Have you tried that link on www.archive.org ? Maybe the target of that link is saved there.
Title: Re: Rexx Socket / SMTP
Post by: Per E. Johannessen on May 04, 2019, 12:59:16 am
Found somewhere a link to rxhelo.cmd, but unfortunately the link was not available anymore.

Have you tried that link on www.archive.org ? Maybe the target of that link is saved there.

It took me to an "archive-site" but got msg that it was unavailable
Title: Re: Rexx Socket / SMTP
Post by: Per E. Johannessen on May 04, 2019, 01:02:42 am
I've found another example written in REXX: John Small's ReleaseTool.cmd of FM/2. See the fm2/trunk source directory. It's much shorter than RexxMail.cmd, but regarding emails, it's only able to send them.

Logged in but still I get "no permission" when I try to read the file.
Title: Re: Rexx Socket / SMTP
Post by: Neil Waldhauer on May 04, 2019, 01:39:43 am
I just did this myself.

Get Weasel and the extra tool qmail. Qmail.cmd is a rexx script to send e-mails. It uses Weasel to actually send. I'm also using STunnel to do the SSL because my ISP requires secure e-mail.
Title: Re: Rexx Socket / SMTP
Post by: Alex Taylor on May 04, 2019, 04:13:25 am
It's not SMTP, but my IMAPADD script demonstrates how to use IMAP via REXX to add a message to the remote mail server.
http://www.altsan.org/programming/rexx/index.html#imapadd

I used to use it to have PMMail copy all incoming messages to my IMAP account.
Title: Re: Rexx Socket / SMTP
Post by: Andreas Schnellbacher on May 04, 2019, 12:19:40 pm
I've found another example written in REXX: John Small's ReleaseTool.cmd of FM/2. See the fm2/trunk source directory. It's much shorter than RexxMail.cmd, but regarding emails, it's only able to send them.

Logged in but still I get "no permission" when I try to read the file.
You seem to have tried the trac browser on netlabs.org. It works in some cases, but never for .cmd files. Browsing works reliable via this URL: http://svn.netlabs.org/repos/fm2/trunk/ (http://svn.netlabs.org/repos/fm2/trunk/)

For both trac and the web server browser, you don't have to log in.
Title: Re: Rexx Socket / SMTP
Post by: Per E. Johannessen on May 06, 2019, 09:49:43 pm
Have found various "rexx-sendmail-programs" but none of them can be used since they don't support SSL.

Tried PMMail, which receives mail ok, but unable to send. It has lots of configuration options so most likely
I have not set it up right, (so can't use PMMSEND for now).
(Smtp configuration in Seamonkey is easy and works fine.)

Some more searching lead me to:

https://sourceforge.net/projects/rexxcurl/files/rexxcurl/2.0/rexxcurl20os2_RexxTrans.zip/download

Seems like rexxcurl supports SSL and is the right tool.



Title: Re: Rexx Socket / SMTP
Post by: Dave Yeo on May 07, 2019, 12:40:05 am
Perhaps pipe through stunnel? http://hobbes.nmsu.edu/download/pub/os2/apps/internet/misc/stunnel-4.05-os2.zip (http://hobbes.nmsu.edu/download/pub/os2/apps/internet/misc/stunnel-4.05-os2.zip)
Title: Re: Rexx Socket / SMTP
Post by: David Graser on May 07, 2019, 12:57:15 am
Have found various "rexx-sendmail-programs" but none of them can be used since they don't support SSL.

Tried PMMail, which receives mail ok, but unable to send. It has lots of configuration options so most likely
I have not set it up right, (so can't use PMMSEND for now).
(Smtp configuration in Seamonkey is easy and works fine.)

Some more searching lead me to:

https://sourceforge.net/projects/rexxcurl/files/rexxcurl/2.0/rexxcurl20os2_RexxTrans.zip/download

Seems like rexxcurl supports SSL and is the right tool.

PMMail is tricky to set up.  Doug bissett helped me with my setup.   I made four pics to show how mine is setup.

Try using the same local port numbers I use for secure poxy.   See how these same numbers are used under the Send and Receive Tabs.
Title: Re: Rexx Socket / SMTP
Post by: Valery Sedletski on May 07, 2019, 02:08:51 am
2David Graser: REXXCURL is an interface to cURL, and cURL is for HTTP (including https). How could it
help with SMTP over SSL?

As far as I can see, newer versions of PMMail use stunnel for SMTP over SSL. So, we could use it too
for the same purpose.
Title: Re: Rexx Socket / SMTP
Post by: Valery Sedletski on May 07, 2019, 02:13:50 am
It's not SMTP, but my IMAPADD script demonstrates how to use IMAP via REXX to add a message to the remote mail server.
http://www.altsan.org/programming/rexx/index.html#imapadd

I used to use it to have PMMail copy all incoming messages to my IMAP account.

So, PMMail already can use IMAP, instead of POP3??? Your script should write an email message into
an IMAP folder. But how could it help with sending emails with SMTP?
Title: Re: Rexx Socket / SMTP
Post by: Per E. Johannessen on May 07, 2019, 12:53:10 pm
Thanks David, I tried various port settings and the following works:

Channel definition Outgoing: Server port 465 and Local port 7587

Account settings SEND: Port 587
If I leave "Allow non-secure" unchecked I get a warning; There is no secure Authentication method available for the SEND server.
When checked there is no warning. In both cases it sends the e-mail.

The option "Use secure channel (SSL) is grayed out, so stlll something is wrong.
Title: Re: Rexx Socket / SMTP
Post by: xynixme on May 07, 2019, 02:14:07 pm
IIRC, attachments have to be base64-encoded, but I don't know how they are appended to the message text.
MIME headers and body in a single message text file: https://stackoverflow.com/questions/23340291/attachments-not-recognized-despite-base64-being-sent-in-header (https://stackoverflow.com/questions/23340291/attachments-not-recognized-despite-base64-being-sent-in-header). No Rexx sample code, but you should be able to recognize all required parts while viewing a sample text message with an editor or by using a raw e-mail view mode.

IIRC there's a BASE64 encoder written in Rexx ("ENBASE64.CMD"). Albeit you may want to avoid excessive file-I/O, to avoid running out of shared memory more frequently when the Object Rexx interpreter is in use.

If you need some level of control when external EXEs like MAILTO.EXE and some ENBASE64.EXE are in use, then using a BCC header could be an option to verify that sizes and numbers sent e-mails are matching expectations. If the source code of an e-mailing EXE is available, then a Rexx DLL could be an option too. A BASE64 Rexx DLL function may already exist. If not, then writing that component should be easier than writing an e-mailing Rexx DLL.
Title: Re: Rexx Socket / SMTP
Post by: xynixme on May 07, 2019, 03:45:27 pm
IIRC there's a BASE64 encoder written in Rexx ("ENBASE64.CMD").
A few candidates at Hobbes, to take care of that part: BASE64.ZIP (Rexx CMD file(s)), or Kiewitz' XtraRexx v0.44b (Rexx DLL file).
Title: Re: Rexx Socket / SMTP
Post by: Alex Taylor on May 08, 2019, 01:32:08 am
It's not SMTP, but my IMAPADD script demonstrates how to use IMAP via REXX to add a message to the remote mail server.
http://www.altsan.org/programming/rexx/index.html#imapadd

I used to use it to have PMMail copy all incoming messages to my IMAP account.

So, PMMail already can use IMAP, instead of POP3???

Well, sort of, but only with this script (and only to copy messages to an IMAP account).

Quote
Your script should write an email message into an IMAP folder.

Maybe I'll try extending it to do that some day.

Quote
But how could it help with sending emails with SMTP?

It doesn't, directly. But part of the original question was asking for code to demonstrate how to initialize/use TCP/IP sockets from REXX.
Title: Re: Rexx Socket / SMTP
Post by: Per E. Johannessen on May 14, 2019, 08:03:19 pm
Just an update;  a kind soul has provided code that works using REXXCURL.