Jump to content

Sending Mail with REXX: Difference between revisions

From EDM2
mNo edit summary
No edit summary
 
(4 intermediate revisions by one other user not shown)
Line 2: Line 2:


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


[ This article was taken from Dave Briccetti's OS/2 Warp Programming Tips
This tip demonstrates sending email to a list of addresses using REXX, SMTP, and TCP Sockets.
and Samples web site with permission. - Editor ]


This tip demonstrates sending email to a list of addresses using REXX,
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.
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? ===
=== 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.


When the OS/2 Bay Area User Group lost its automated email mailing list
First I wrote a simple REXX command to call SENDMAIL for each address in the list:
server in November, 1995, I was forced to find another way to notify our
<code>
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:
 
  /* REXX */
  /* REXX */
  arg MailingList
  arg MailingList
Line 30: Line 21:
   || rec || '"'
   || rec || '"'
  end
  end
</code>
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.


This method was very slow, as long as a minute or more for each address
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.
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
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.
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 ===
=== 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.
Here's the result of running the program with only a singler 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-blob.best.net Sendmail 8.6.12/8.6.5 ready at Thu, 16 Nov 1995 02:57:09 -0800
  220 ESMTP spoken here
  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.
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
  EHLO john
 
This is the extended SMTP Hello command which starts the protocol and identifies us.
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-blob.best.net Hello daveb.vip.best.com [205.149.171.251], pleased to meet you
  250-SIZE
  250-SIZE
  250 HELP
  250 HELP
 
This response (code 250) tells us that the server supports extended SMTP, including the two extensions, SIZE and 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
  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.
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
  250 daveb@davebsoft.com... Sender ok
Again the 250 tells us things are going well.
Again the 250 tells us things are going well.
  RCPT TO:daveb@davebsoft.com
  RCPT TO:daveb@davebsoft.com
We specify the recipient.
We specify the recipient.
  250 daveb@davebsoft.com... Recipient ok
  250 daveb@davebsoft.com... Recipient ok
All still ok.
All still ok.
  DATA
  DATA
We indicate we're ready to send the body of the message.
We indicate we're ready to send the body of the message.
  354 Enter mail, end with "." on a line by itself
  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:
The 354 tells us to send the data. Send message body. Don't forget to include Subject:
  Subject: message subject
  Subject: message subject
  Message text
  Message text
 
Got the answer:
Got hte answer:
 
  250 CAA19942 Message accepted for delivery
  250 CAA19942 Message accepted for delivery
It worked.
It worked.
  QUIT
  QUIT
We're done with the SMTP conversation.
We're done with the SMTP conversation.
  221 blob.best.net closing connection
  221 blob.best.net closing connection
And so is the server.
And so is the server.


You can also get the completed REXX program from hobbes:
You can also get the completed REXX program from [[Hobbes]]:
 
* {{FileLink|MailList_1995-11-30.zip}}: Send Email Message to a Mailing List Via SMTP, Using the REXX Socket Interface
[http://hobbes.nmsu.edu/cgi-bin/h-search?key=maillist.zip Send Email Message to a Mailing List Via SMTP, Using the REXX Socket Interface]
 
or here:
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
* [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 Archived Site]


[[Category:Scripting_Articles]]
[[Category:REXX Articles]]
[[Category:REXX]]

Latest revision as of 17:05, 27 January 2024

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:

/* REXX */
arg MailingList

do while lines(MailingList)
   rec = linein(MailingList)
   'sendmail -Ce:\mptn\etc\sendmail.uml -af msg -f daveb@davebsoft.com"',
  || rec || '"'
end

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 the 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:

or here: