Automated e-mail sending

I don't want to encourage spammers, but there are occasions it is sensible to send multiple addresses the same ( or a customised-) email.

This is easy if you download a copy of sendemail.exe and from Caspian. NB I only tested on Windows XP. Put the files in a folder/directory, along with this LB code. The code version below assumes you want to add two attachments- to test this part, put in a txt-file and a bitmap named as shown. It also assumes you have created a file with a series of e-mail addresses and saved it in the folder with title 'emailAddresses_1.csv" or your choice of name.- eg

You of course need to change the e-mail server address, plus your user-name and password.

After running the LB program there will be a log file created in the same directory. Useful if it seems not to be working. It's been trouble-free for me. Note the use of chr$(34) to surround file-names-including-spaces.

'This program requires sendemail.exe and in the same directory,
'    available free from Caspian's SendEmail Site. TLS version also available.
'Commandline Switches:
'   Required:
'    -f ADDRESS from (sender) email address
'    At least one recipient required via -t, -cc, or -bcc
'    Message body required via -m, STDIN, or -o message-file=FILE
'   Common:
'    -t ADDRESS   [ADDR ...] to email address(es)
'    -u SUBJECT   message subject
'    -m MESSAGE   message body
'    -s SERVER    [:PORT]
'   Optional:
'    -a FILE      [FILE ...] file attachment(s)
'    -cc ADDRESS  [ADDR ...] cc email address(es)
'    -bcc ADDRESS [ADDR ...] bcc email address(es)
'    -xu USERNAME username for SMTP authentication
'    -xp PASSWORD password for SMTP authentication

    from$       = ""
    username$   = "username"
    password$   = "password"
    'recipient$  = ""                                    '   These are read from a file
    server$     = ""

    subject$    = chr$( 34) +"Subject- an unmissable offer." +chr$( 34)     '   Use quotes to allow spaces in text.
    message$    = chr$( 34) +"Send me 100 dollars for the secret of my success." +chr$( 34)

    attach$     = "attachmentB.txt attachmentA.bmp"
    logfile$    = "sendemail.log"

    filedialog "Open address file for processing", "*.txt; *.csv", fname$
    if fname$ ="" then goto [openAddresses]

    open fname$ for input as #addressFile

    pathLength =len( DefaultDir$)

    print "Sending e-mails to addresses held in "; mid$( fname$, pathLength +2)

    while eof( #addressFile) <>-1
        input #addressFile, recipient$
        cmd$ =_
        " -f ";  from$;_             'from
        " -t ";  recipient$;_        'to
        " -u ";  subject$;_          'subject
        " -s ";  server$;_           'server
        " -m ";  message$;_          'message
        " -a ";  attach$;_           'file to attach
        " -l ";  logfile$;_          'file to log result in
        " -xu "; username$;_         'smtp user name
        " -xp "; password$           'smtp password not given so will ask in a CMD window
       run "sendEmail.exe "; cmd$, HIDE
       print "   "; recipient$       'Delay 5 seconds before sending another email
       'print "sendEmail.exe"; cmd$
       calldll #kernel32, "Sleep", 5000 as ulong, r as void

    close #addressFile
    print "All sent. Done."


I have many other Liberty BASIC pages indexed at Diga Me!