Sending Mail with REXX

Written by Dave Briccetti

Introduction
[This article was taken from Dave Briccetti's OS/2 Warp Programming Tips and Samples web site with permission. - Editor]

This tip demonstrates sending email to a list of addresses using REXX, SMTP, and TCP Sockets.

If you are a REXX, SMTP, or Sockets expert and you see any errors or possible improvements to this tip, please share your knowledge with me.

Why Bother?
When the OS/2 Bay Area User Group lost its automated email mailing list server in November, 1995, I was forced to find another way to notify our members about our meetings. I had the email addresses in an ASCII file, dumped from our member database.

First I wrote a simple REXX command to call SENDMAIL for each address in the list: This method was very slow, as long as a minute or more for each address because SENDMAIL was doing a great deal of domain name service activity; this generated a lot of traffic over my 28.8K bps modem to the domain name server at my Internet service provider. SENDMAIL actually connected with each recipient's mail system, and often there were delays in connecting. OS/2 email programs such as Post Road Mailer and PMMail very quickly send the mail to an intermediary which actually delivers the mail.

To send mail these OS/2 email programs use the Simple Mail Transfer Protocol (SMTP). To create a communication channel, these programs use TCP Sockets, probably from C or C++ language.

I decided to use the same approach, but since I had recently discovered the REXX sockets interface I thought I'd give it a go with REXX.

The Why's and How's
Here's the result of running the program with only a single user email address in the mailing list file, with commentary interspersed. The actual SMTP commands we are sending are shown as well. 220-blob.best.net Sendmail 8.6.12/8.6.5 ready at Thu, 16 Nov 1995 02:57:09 -0800 220 ESMTP spoken here This is what the mail server says when we connect to it. The 220 code tells us that all is well and we can continue. EHLO john This is the extended SMTP Hello command which starts the protocol and identifies us. 250-blob.best.net Hello daveb.vip.best.com [205.149.171.251], pleased to meet you 250-SIZE 250 HELP This response (code 250) tells us that the server supports extended SMTP, including the two extensions, SIZE and HELP. MAIL FROM:daveb@davebsoft.com SIZE=776 We begin a mail message, identifying the sender, and providing the size of the message. The SIZE parameter is an SMTP extension, and we are supporting it because the server supports it. 250 daveb@davebsoft.com... Sender ok Again the 250 tells us things are going well. RCPT TO:daveb@davebsoft.com We specify the recipient. 250 daveb@davebsoft.com... Recipient ok All still ok. DATA We indicate we're ready to send the body of the message. 354 Enter mail, end with "." on a line by itself The 354 tells us to send the data. Send message body. Don't forget to include Subject: Subject: message subject Message text Got hte answer: 250 CAA19942 Message accepted for delivery It worked. QUIT We're done with the SMTP conversation. 221 blob.best.net closing connection And so is the server.

You can also get the completed REXX program from Hobbes:

Send Email Message to a Mailing List Via SMTP, Using the REXX Socket Interface

or here: http://web.archive.org/web/20000122041807/http://www.davebsoft.com/Programming/tips/Tips/Internet/Send_Mail_to_an_Email_List_wit/send_mail_to_an_email_list_wit.html