#!/bin/csh -f # jsend # ------------------------------------------------------------------------- # Shell script to send Internet mail from the command line, allowing # interactive or batch mail sends. Type send -h for usage info. # ------------------------------------------------------------------------- # Globals: # 1. Requires existence of JSEND_NAME environment variable, for example: # setenv JSEND_NAME stluka@voicenet.com # 2. In interactive mode (1 or less parameters), uses JSEND_EDITOR, or EDITOR, # environment variable to determine what text editor to use. Default: vi # Default: setenv JSEND_EDITOR ew # 3. Creates and deletes temporary files with the following names in the # current working directory: # sendmail.1 # sendmail.4 # sm_temp.bat # 4. Recognizes environment variables of the form JSEND_ALIAS_alias as aliases # for mail addresses. # ?? Not yet implemented # 5. Checks for existence of JSEND_QUIET environment variable to determine # whether to run in "quiet" mode (suppressing output -- including # password prompt) from IMPORT command). # 6. Uses value of JSEND_SIGNATURE environment variable as name of file # to automatically append to the message being sent. # 7. Uses value of JSEND_MESSAGE_LOG environment variable as name of file # to log each sent message to. (Note: Names of attachments are logged # but the attachments themselves are not.) # 8. Uses value of JSEND_LISTS_DIR environment variable as name of # directory containing *.LIS mailing list files. # ------------------------------------------------------------------------- # Implementation Notes: # ------------------------------------------------------------------------- # Anticipated Changes: # 1. Better temp file handling: # - Not created in current directory (in case user has no write access) # - Avoid collisions with other concurrent uses of this file. # 2. Support batch subject line longer than 7 words (in quotes, perhaps?). # 3. Don't require pre-defined JSEND_NAME environment variable. # 4. Deal with user errors better: # - What if blank line before body line is deleted? # - What if JSEND_NAME is specified in quotes? # 5. Better mailing list and bulletin board handling. Currently can't # specify anything except 1-word name as recipient on command line. # 6. Multiple recipients in batch mode. # 7. Cc: and Bcc: recipients in batch mode. # ------------------------------------------------------------------------- # Revision History: # $Log: D:/FRED/NTBIN/RCS/SEND.BAV $ # # Rev 1.17 24 Mar 2009 08:57:26 FPS0 # - Moved from Windows to Unix (Mac OS X) # # Rev 1.16 05 Oct 1995 10:35:00 FPS0 # - Moved from OS/2 to NT (use DOS IMPORT command, OS2 IMPORT2) # - Added support for editor and import command being batch files (use CALL). # - Added support for a message log via CCMAIL_MESSAGE_LOG env. var. # # Rev 1.15 12 May 1995 14:29:02 FPS0 # - Updated from version 3.31 of Import to version 5.12. # Had to stop putting text on Contents: line. # # Rev 1.14 12 May 1995 13:31:52 FPS0 # - Updated to use new location of IMPORT command (IMEX3-31, not IMP-EXP.331). # # Rev 1.13 11 May 1995 13:32:24 FPS0 # - Added error handling for unexpected error messages like when the # PostOffice is down. # # Rev 1.12 07 Apr 1995 21:02:40 FPS0 # - Added support for automatic use of signature file. # # Rev 1.11 10 Oct 1994 20:16:20 FPS0 # - Added support for automatic use of RRQ option. # # Rev 1.10 10 Oct 1994 14:28:38 FPS0 # - Added beep when IMPORT fails. # # Rev 1.9 14 Apr 1994 15:12:08 FPS0 # - Added support for aliases (environment variables) for addresses. # - Added environment variable switch to control quiet mode. # - Factored all DOS- or OS/2-specific code into 2 lines at top of file. # # Rev 1.8 05 Apr 1994 11:37:10 FPS0 # - Modified to accept full names (firstname lastname) instead of 4-char # userids. # - Modified to accept CCNAME or LOGINAME as well as FULL_NAME env. var. # since these are likely to be set up for other reasons. # # Rev 1.7 05 Apr 1994 10:37:38 FPS0 # - Modified to echo number of messages imported. # # Rev 1.6 24 Feb 1994 13:18:48 FPS0 # - Suppressed verbose messages of IMPORT command, and added explicit test # for CCMAIL.UND file as indication of failure to send. # # Rev 1.5 30 Nov 1993 10:00:12 FPS0 # - Moved mailing list and bboard names to a separate LISTS.TXT file, # similar to NAMES.TXT. # # Rev 1.4 30 Nov 1993 09:53:06 FPS0 # - Added mailing list and bboard names to help file. # # Rev 1.3 29 Nov 1993 15:36:52 FPS0 # - Now fills in cc: to sender even in interactive mode. # # Rev 1.2 10 Nov 1993 15:36:14 FPS0 # - Added support (via CCMAIL_INCLUDE) for sending file items. # - Defaulted subject line to file name. # - Added support for specifying only the recipient on the command line # (still goes into interactive mode, but fills in To: line). # - Redirected output of DEL and REN to NUL (for sake of 4OS2 and 4DOS # users). # # Rev 1.1 08 Nov 1993 15:12:28 FPS0 # - Cleaned up and added help and documentation. # # Rev 1.0 05 Nov 1993 19:41:24 FPS0 # Initial revision. # ------------------------------------------------------------------------- if ("$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [options]" echo " $0:t [options] e-mail_address [file [subject]]]" echo " $0:t [options] alias [file [subject]]" echo "Options: -q = Quick. Email only. No social media." echo "Aliases: Define aliases as: setenv JSEND_ALIAS_fps0 stluka@voicenet.com" echo "Examples: $0:t" echo " $0:t stluka@voicenet.com" echo " $0:t stluka@voicenet.com /user/userinit.cmd" echo " $0:t stluka@voicenet.com /user/userinit.cmd Copy of my USERINIT file." echo " $0:t stluka@voicenet.com none Subject line only. No file sent." echo " $0:t fps0" echo " $0:t fps0 /user/userinit.cmd" echo " $0:t fps0 /user/userinit.cmd Copy of my USERINIT file." echo " $0:t fps0 none Subject line only. No file sent." echo "See comments at top of file for more details." exit 1 endif set social_media = "true" if ("$1" == "-q") then set social_media = "false" shift endif # # Check for missing required environment variable names # if ("`printenv JSEND_NAME`" == "") then echo "Error: JSEND_NAME must be sender's e-mail address." exit 1 endif if ("`printenv JSEND_LISTS_DIR`" == "") then echo "Error: JSEND_LISTS_DIR must be folder containing mailing lists." exit 1 endif # # Global references (files, environment variables, etc) # setenv SMTP_SERVER $TRIDENT setenv SMTP_PORT 8325 set mail_cmd = "javamail" set editor_cmd = "`printenv JSEND_EDITOR`" if ("$editor_cmd" == "") set editor_cmd = "`printenv EDITOR`" if ("$editor_cmd" == "") set editor_cmd = "vi" set temp_file01 = "sendmail.1" set temp_file04 = "sendmail.4" set temp_file05 = "sm_temp.bat" # # Check for existing temp files to avoid overwriting them. # if (-e $temp_file01:q) then echo "Error: File $temp_file01 already exists." exit 1 endif if (-e $temp_file04:q) then echo "Error: File $temp_file04 already exists." exit 1 endif if (-e $temp_file05:q) then echo "Error: File $temp_file05 already exists." exit 1 endif #??# #??# If the first param is a ccmail "alias", expand it and call this file #??# recursively with the expanded value. #??# #??# Note: Test an explicit recursion flag to avoid more than one level #??# of recursion. #??# #??if "$JSEND_RECURRED" == "TRUE" goto NO_EXPAND #??set JSEND_RECURRED = "TRUE" #??set JSEND_EXPANDED_ALIAS = #??echo if "$(JSEND_ALIAS_$1)" == "" goto EXIT > $temp_file05:q #??echo set JSEND_EXPANDED_ALIAS = "$(JSEND_ALIAS_$1)" >> $temp_file05:q #??echo :EXIT >> $temp_file05:q #??call $temp_file05:q #??del $temp_file05:q >nul #??if "$JSEND_EXPANDED_ALIAS" == "" goto NO_EXPAND #??$0:q $JSEND_EXPANDED_ALIAS:q $2 $3 $4 $5 $6 $7 $8 $9 #??goto EXIT #??:NO_EXPAND # # Build the header lines, defaulting the subject line to the name of # the file being sent if any. # set recipient = $1:q set file_to_send = if ("$1" != "") then shift set file_to_send = $1:q if ("$1" != "") then shift endif endif if ("$1" == "") then set subject = $file_to_send:q else set subject = "$*" endif if ("$subject" == "") then set subject = "xxx Tip: ..." endif echo "From: $JSEND_NAME" >> $temp_file01:q echo "Copyright: Copyright (c) 2021, Bristle Software, Inc." >> $temp_file01:q echo "List: " >> $temp_file01:q echo "To: $recipient" >> $temp_file01:q echo "cc: " >> $temp_file01:q echo "bcc: $JSEND_NAME" >> $temp_file01:q echo "Subject: $subject" >> $temp_file01:q echo "" >> $temp_file01:q # # If no file to send, load editor with a mail message template. # Else mail the file. # if ("$file_to_send" == "") then # # Load message template file, list of valid addresses, and help files # into the editor, allow user to edit message, then fill in more header # lines, and send the file. # echo "Help Information" > $temp_file04:q echo "----------------" >> $temp_file04:q echo "- Use multiple To: lines to send to multiple primary addresses." >> $temp_file04:q echo "- Use multiple Cc: and Bcc: lines to send to multiple secondary" >> $temp_file04:q echo " addresses." >> $temp_file04:q echo "- All text below the first blank line is the text of the message." >> $temp_file04:q echo "- Lists of addresses are stored in other buffers of this editor." >> $temp_file04:q if ("`printenv JSEND_SIGNATURE`" != "") then cat $JSEND_SIGNATURE:q >> $temp_file01:q endif echo Starting editor: $editor_cmd... $editor_cmd:q $temp_file04:q $JSEND_LISTS_DIR:q/*.lis $JSEND_MESSAGE_LOG:q* ~/fred/admin/out.mai $temp_file01:q rm $temp_file04:q else # # Prefix the user specified file with the required header lines and # send it as the body of a mail message. # if ("$file_to_send" == "none") then echo "(No message body)" >> $temp_file01:q else cat $file_to_send:q >> $temp_file01:q endif if ("`printenv JSEND_SIGNATURE`" != "") then cat $JSEND_SIGNATURE:q >> $temp_file01:q endif endif # # Send the message. Copy the message to a message log file first. # if ("`printenv JSEND_MESSAGE_LOG`" != "") then echo Logging message in $JSEND_MESSAGE_LOG... cat $temp_file01:q >> $JSEND_MESSAGE_LOG:q endif if ("`printenv JSEND_QUIET`" == "") then # Prompt the interactive user, if any, for whether to send. if ("$file_to_send" == "") then set send = `promptloop "Send the message (y/n)? " y n` if ("${send}" == "n") then echo "Mail not sent. $temp_file01 not deleted." exit 0 endif endif endif $mail_cmd $temp_file01:q |& tee tee.log set rc = $status # Save tee.log before doing social stuff in case I hit Ctrl-C there. cat tee.log >> $JSEND_MESSAGE_LOG:q rm tee.log if ($rc == 0) then rm $temp_file01:q # Open social media sites to post links there to the latest tip if ("$social_media" == "true") then social endif else echo "Error $rc occurred. $temp_file01 not deleted." endif