• Sending internet e-mail

    From Amcleod@VERT to All on Mon Aug 20 01:34:00 2001
    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
  • From Amcleod@VERT to All on Mon Aug 20 01:48:00 2001
    RE: Sending internet e-mail
    BY: Amcleod to All on Mon Aug 20 2001 12:34 pm

    sprintf str "To: %s\n" to_address
    SOCKET_WRITE sock str

    #----------------------#
    # send body of message #
    #----------------------#

    Oooooops! :-/ <-- red face!

    In cleaning up and removing _my_ address and replacing it with example.com, etc, I killed an important line:

    Just before sending the BODY of the message you need to insert a blank line to end the HEADER. So you need to add the lines:

    SET str "\n"
    SOCKET_WRITE sock str

    Just before sending the body of the message.

    OR, you can add an extra newline ("\n") to the previous line, in this case the "to_address" line -- which could be written as

    sprintf str "To: %s\n\n" to_address

    just so you get the extra newline between the header and body.

    Sorry about that..... ;-)


    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net