There have been a few questions recently about sending internet e-mail from a BAJA module. I went playing about with the SOCKET_* stuff and came up with this module:
#----------------------------------------------------------#
# demo program for sending internet e-mail via SMTP server #
#----------------------------------------------------------#
!INCLUDE SBBSDEFS.INC
STR mailserver helo_domain from_address to_address
INT sock SMTP_port
SET helo_domain "example.com"
SET mailserver "mail.example.com"
SET from_address "
sysadmin@example.com"
SET to_address "
someuser@example.com"
SET SMTP_port 25
#-------------------------------#
# Create connection with server #
#-------------------------------#
SOCKET_OPEN sock
SOCKET_CONNECT sock mailserver SMTP_port
#------------------#
# initial dialogue #
#------------------#
sprintf str "helo %s\n" helo_domain
SOCKET_WRITE sock str
sprintf str "mail from: %s\n" from_address
SOCKET_WRITE sock str
sprintf str "rcpt to: %s\n" to_address
SOCKET_WRITE sock str
SETSTR "data\n"
SOCKET_WRITE sock str
#---------------------------------------------------------#
# send additional headers (like "Subject:", "Date:", etc) #
#---------------------------------------------------------#
SETSTR "Subject: This is a test\n"
SOCKET_WRITE sock str
sprintf str "To: %s\n" to_address
SOCKET_WRITE sock str
#----------------------#
# send body of message #
#----------------------#
SETSTR "The quick brown fox\n"
SOCKET_WRITE sock str
SETSTR "jumps over the lazy dog\n"
SOCKET_WRITE sock str
#---------------------------------------------------------#
# terminate body of message, close connection with server #
#---------------------------------------------------------#
SETSTR "\n.\n"
SOCKET_WRITE sock str
SETSTR "quit\n"
SOCKET_WRITE sock str
SOCKET_CLOSE sock
True RAABA software (RAABA = Rough As A Bruin's Bottom), so use it at your
own risk. Basically, it connects to the SMTP server of your choice (your ISP if you aren't running your own) and initiates a dialogue to get the mail sent.
I say "dialogue" but it's really more of a MONOlogue. it _completely_ ignores what the server sends back, so if any problems occur it will ignore them. IOW, there is NO error checking at all -- please add to taste.
You can see what the server responds by sticking in a SOCKET_READLINE/PRINT pair after each SOCKET_WRITE, but when I tried that the buffer was always prefixed with a series of garbage characters. Can anybody say why/how to avoid? If the garbage can be avoided some rudimentary error checking should be fairly easy, since each response begins with a numeric result code that should be easily parsed to indicate success/failure.
Comments please!
---
þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net