• Sending internet e-mail

    From Amcleod@VERT to All on Mon Aug 20 05:34:56 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 05:48:06 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ã