how to request a "read" or "delivered" receipt for mails


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Network how to request a "read" or "delivered" receipt for mails

Dears,
I've written a script which allows me to send mails in different formats with different attaches. Now I still want to add a feature to this script. My users would like to be able to receive a "read" or "delivered" receipt for their mails.
The script send mails on behalve of an specific exchange user and is triggered from a web page or another script or a DB. The user (not the unix account) on which behalf the mail will be sent needs confirmation about it. Which codes do I need to use to implement this request ?
Smilie
P.S.: any enhancements are also welcom. For example the trick I do with mpack, isn't there a more easy way to convert a binary ?
Something in the way of input stream | converter | output stream ?


Underneath you find the script.
Code:
#!/usr/bin/ksh 

########################################
# Script to send mails in HTML or TEXT, with or whitout attach 
# Author : LP 
# Syntax : mailto.sh <TYPE> <SUBJECT> <BODY> <TO_ADDRES> [FROM_ADDRES] [<ATTACHEMENT> <ATTACH_TYPE>] 
########################################

### vars 
################## 
export min_para=4 
export log=`date +%d%m%Y%H%M%S`.$#.log 
first_attach=0 

### functions 
################## 

function Error 
{ 
mailx -s "ERROR TO SEND MAIL " $FROM_ADDRES < $log; 
rm $log; 
exit 1; 
} 

function lower 
{ 
echo $1 | tr [:upper:] [:lower:]; 
} 

function upper 
{ 
echo $1 | tr [:lower:] [:upper:]; 
} 

function Syntax 
{ 
echo "Syntax = mailto.sh <TYPE> <SUBJECT> <BODY> <TO_ADDRES> [FROM_ADDRES] [<ATTACHEMENT> <ATTACH_TYPE>]"; 
echo "Where TYPE = \"t\" for text only mails"; 
echo " \"h\" for html only mails"; 
echo " \"ta\" for text with an attachement"; 
echo " \"ha\" for html with an attachement"; 
echo "You MUST provide a TYPE, this is Mandatory"; 
echo "Where SUBJECT = the subject of the mail (Mandatory)"; 
echo "Where BODY = the name of the file which contains the body for the mail (Mandatory)"; 
echo "Where TO_ADDRES = the mailadress of the recipients (Mandatory)"; 
echo " you can provide as many adresses as you like."; 
echo" in this case you need to enclose the adresses with double quotes"; 
echo" and seperate them with a space."; 
echo " example: \"adres1@exchage.bc adres@aserver.com adres3@belgacom.be\""; 
echo "Where FROM_ADDRES = the mailadress of the sender (Optional)"; 
echo " If not provided, the adres of the unix account will be used."; 
echo "Where ATTACHEMENT = the attachement that has to be sent with the mail (Optional)"; 
echo "Where ATTACH_TYPE = the type of attachement that has to be sent with the mail (Optional)"; 
echo " this type can be set to \"t\" (plain text files) "; 
echo " this type can be set to \"b\" (binary files) "; 
echo " If the type is not provided it will be set to \"t\""; 
echo "The attachement together with the type is 1 parameter you must provide both between quotes"; 
echo " example : \"attach1.txt t\" \"attach2.exe b\" \"attach3.xls b\""; 
echo "----------------------------------------------------------------------------------------------------------------------"; 
echo "Example : mailto.sh ta \"test om te testen\" a_body.txt id079725@exchange.bc patrick@e-lelie.be \"attach.txt t\";"; 
echo "----------------------------------------------------------------------------------------------------------------------"; 
} 

function gres 
{ 
if [ $# -lt "3" ] 
then 
  echo "Usage: gres pattern replacement file"; 
  exit 1; 
fi 
pattern=$1; 
replacement=$2; 
if [ -f $3 ] 
then 
  file=$3; 
else 
  echo "$3 is not a file"; 
  exit 1; 
fi; 
A="`echo | tr '\012' '\001' `"; 

sed -e "s$A$pattern$A$replacement$A" $file; 
} 

function striphtml 
{ 
gres "<[^>]*>" " " $1 > $1.txt; 
grep "<[^>]*>" $1.txt >/dev/null 2>&1; 
while (( $? == 0 )) 
do 
  gres "<[^>]*>" " " $1.txt > $1.tmp; 
  mv $1.tmp $1.txt; 
  grep "<[^>]*>" $1.txt >/dev/null 2>&1 
done 
} 

function mailhead 
{ 
echo "From: $1"; 
recipient=`echo $2 | tr -s " " | tr " " ";"` 
echo "To: $recipient"; 
echo "Subject: $3"; 
echo "Mime-Version: 1.0"; 
} 

function pack_attach 
{ 
while (( $# > 1 )) 
do 
  ATTACH=$1 
  ANAME=`basename $ATTACH` 
  ATYP=$2 
  echo "------NextPart" 
  echo "Content-Type: application/octet-stream;" 
  echo " name=\"$ATTACH\"" 
  if [[ "$ATYP" = [bB] ]] 
  then 
    echo "Content-Transfer-Encoding: base64" 
    mpack -s "" -o $ATTACH.enc $ATTACH 
    lines=`cat $ATTACH.enc | wc -l` 
    x=0 
    while read line 
    do 
      (( x=$x+1 )) 
      if (( $x > 14 && $x < $lines - 1 )) 
      then 
        echo $line >> $ATTACH.tmp 
      fi 
    done < $ATTACH.enc 
    mv $ATTACH.tmp $ATTACH.enc 
    echo "Content-Disposition: attachment;" 
    echo " filename=\"$ANAME\"" 
    echo "" 
    cat $ATTACH.enc 
    rm $ATTACH.enc 
    echo "" 
    shift 
    shift 
  else 
    if [[ "$ATYP" = [tT] ]] 
    then 
      echo "Content-Transfer-Encoding: 7 bit" 
      echo "Content-Disposition: attachment;" 
      echo " filename=\"$ANAME\"" 
      echo "" 
      cat $ATTACH 
      echo "" 
      shift 
      shift 
    else 
      echo "Content-Transfer-Encoding: 7 bit" 
      echo "Content-Disposition: attachment;" 
      echo " filename=\"$ANAME\"" 
      echo "" 
      cat $ATTACH 
      echo "" 
      shift 
    fi 
  fi 
done 
} 

function textonly 
{ 
echo "Content-Type: text/plain;"; 
echo " charset=\"ISO-8859-1\""; 
echo ""; 
cat $1; 
} 

function htmlonly 
{ 
echo "Content-Type: multipart/alternative;"; 
echo " boundary=\"----NextPart\""; 
echo ""; 
echo "This message is in MIME format. Since your mail reader does not understand"; 
echo "this format, some or all of this message may not be legible."; 
echo ""; 
echo "------NextPart"; 
echo "Content-Type: text/plain;"; 
echo " charset=\"ISO-8859-1\""; 
echo "" 

striphtml $1; 
cat $1.txt; 
rm $1.txt; 

echo "------NextPart"; 
echo "Content-Type: text/html;"; 
echo " charset=\"ISO-8859-1\""; 
echo "Content-Transfer-Encoding: quoted-printable" 
echo ""; 
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"; 

cat $1; 

echo "" 
echo "------NextPart--"; 
} 

function textplus 
{ 
echo "Content-Type: multipart/mixed;" 
echo " boundary=\"----NextPart\"" 
echo "" 
echo "This message is in MIME format. Since your mail reader does not understand" 
echo "this format, some or all of this message may not be legible." 
echo "" 
echo "------NextPart" 
textonly $1 
echo "" 
shift 
pack_attach $@ 

echo "------NextPart--" 
} 

function htmlplus 
{ 
echo "Content-Type: multipart/mixed;" 
echo " boundary=\"----NextPart\"" 
echo "" 
echo "This message is in MIME format. Since your mail reader does not understand" 
echo "this format, some or all of this message may not be legible." 
echo "" 
echo "------NextPart" 
htmlonly $1 
echo "" 
shift 
pack_attach $@ 

echo "------NextPart--" 
} 

function sendFile 
{ 
mailtje=mail`date +%H%M%S%d%m%m%y`.msg 
mailhead $FROM_ADDRES "$TO_ADDRES" "$SUBJECT" > $mailtje; 

case $TYPE in 
t) textonly $BODY >> $mailtje;; 
h) htmlonly $BODY >> $mailtje;; 
ta) textplus $BODY $ATTACHMENTS >> $mailtje;; 
ha) htmlplus $BODY $ATTACHMENTS >> $mailtje;; 
esac; 
cat $mailtje | /usr/sbin/sendmail $TO_ADDRES 
rm $mailtje 


} 

# Assign parameters 
#################### 

TYPE=`lower $1`; 
SUBJECT=$2; 
BODY=$3; 
TO_ADDRES=$4; 
FROM_ADDRES=$5; 

# Check parameters 
################## 

x=0 
if (( $# >= $min_para )) 
then 
  echo "Number of parameters is acceptable" > $log 
  else 
  echo "Wrong number of parameters" >> $log 
  echo "$# parameters given" >> $log 
  echo "Given Parameters : $@ " >> $log 
  (( x=$x+1 )) 
fi 

if [[ "$TYPE" = "t" || "$TYPE" = "h" || "$TYPE" = "ta" || "$TYPE" = "ha" ]] 
then 
  echo "Type has correct value" >> $log 
else 
  echo "Type has incorrect value" >> $log 
  (( x=$x+1 )) 
fi 

if [[ -f $BODY ]] 
then 
  echo "Body exists" >> $log 
else 
  echo "Body doesn't exist" >> $log 
  (( x=$x+1 )) 
fi 

checka=`echo $TO_ADDRES | cut -d "@" -f1` 
if [[ "$TO_ADDRES" = "$checka" ]] 
then 
  echo "Adres is not valid" >> $log 
  (( x=$x+1 )) 
else 
  echo "Adres is valid" >> $log 
fi 

if [[ "$FROM_ADDRES" = "" ]] 
then 
  mach=`uname -n` 
  user=`whoami` 
  FROM_ADDRES=$user@$mach.bc 
  first_attach=5 
else 
  if [[ -f `echo $FROM_ADDRES | cut -d" " -f1` ]] 
  then 
    mach=`uname -n` 
    user=`whoami` 
    first_attach=5 
    FROM_ADDRES=$user@$mach.bc 
  else 
    first_attach=6 
  fi 
fi 

par=1 
while (( $par < $first_attach )) 
do 
  (( par=$par+1 )) 
  shift 
done 

if [[ "$TYPE" = "ta" || "$TYPE" = "ha" ]] 
then 
  ATTACHMENTS="" 
  while (( $# > 0 )) 
  do 
    if [[ -f `echo $1 | cut -d" " -f1` ]] 
    then 
      ATTACHMENTS=`echo "$ATTACHMENTS $1"` 
    else 
      echo "this attach \"$1\" is NOT found" >> $log 
      (( x=$x+1 )) 
    fi 
    shift 
  done 
fi 

if (( $x > 0 )) 
then 
  Syntax >> $log 
  Error 
fi; 

# Send the mail 
################### 

sendFile 
rm $log

# 2  
Re: how to request a "read" or "delivered" receipt for mails

Quote:
Originally posted by plelie2
Dears,
I've written a script which allows me to send mails in different formats with different attaches. Now I still want to add a feature to this script. My users would like to be able to receive a "read" or "delivered" receipt for their mails.

Please see: http://www.sendmail.org/~ca/email/dsn.html
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #836
Difficulty: Medium
SOAP is a data serialization specification.
True or False?

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Read from "list1" and list matches in "list2"

I want to print any matching IP addresse in List1 with List 2; List 1 List of IP addresses; 161.85.58.210 250.57.15.129 217.23.162.249 74.76.129.101 30.221.177.237 3.147.200.59 170.58.142.64 127.65.109.33 150.167.242.146 223.3.20.186 25.181.180.99 2.55.199.32 (3 Replies)
Discussion started by: lewk
3 Replies

5. Solaris

The slices "usr", "opt", "tmp" disappeared!!! Help please.

The system don't boot. on the screen appears following: press enter to maintenance (or type CTRL-D to continue)...I checked with format command. ... the slices "0-root","1-swap","2-backup" exist. ...the slises "3-var","6-usr" -unassigned. :( (16 Replies)
Discussion started by: wolfgang
16 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

Featured Tech Videos