1837962 Members
2596 Online
110124 Solutions
New Discussion

Sendmail

 
David Dangerfield_1
Frequent Advisor

Sendmail

Wanting to see about getting the syntax for using sendmail in a script.
4 REPLIES 4
Ivan Ferreira
Honored Contributor

Re: Sendmail

Do you want to send a mail to a user using the sendmail command? Use:

sendmail user@domain.com < /path/to/file/body

You can also use:

mailx -s "Subject" < /path/to/file/body
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Peter Nikitka
Honored Contributor

Re: Sendmail

Hi,

to complete Ivan's solution, provide the user(s) the mail is sent as additional arguments:
mailx -s "Subject" user1@dom1 user2@dom2 ... < /path/to/file/body

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Steven E. Protter
Exalted Contributor

Re: Sendmail



Shalom,

Take a look at this:

http://www.hpux.ws/mailfile2

It has some moderate to advanced sendmail scripting in it.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Joel Girot
Trusted Contributor

Re: Sendmail

Hi

some example :

simple text :

(
echo "To: joel "
echo "From: system $(hostname) "
echo
echo "Systeme $(hostname) $(date)"
echo "Update time: The time has been updated"
) 2>&1 | /usr/lib/sendmail -t

text + two attached files :

{
echo "To: loic@host.domain "
echo "From: system $(hostname) "
echo "Cc: joel@host.domain "
echo "Subject: compte rendu de l'analyse des sauvegarde"
echo 'MIME-Version: 1.0'
echo 'Content-type: multipart/mixed; boundary="xxxxyyyzzqzzyyyxxxx"'

#text
echo '--xxxxyyyzzqzzyyyxxxx'
echo ''
echo "Systeme $(hostname) $(date)"
echo "Surveillance de la sauvegarde des PC utilisateurs"
echo "Voir les fichiers joints"

#first attached file
echo '--xxxxyyyzzqzzyyyxxxx'
echo 'Content-Disposition: attachment; filename="'$(basename $tmpfilename)'"'
echo ''
cat "$tmpfilename"

#second attached file
echo '--xxxxyyyzzqzzyyyxxxx'
echo 'Content-Disposition: attachment; filename="'$(basename $fichier_csv)'"'
echo ''
cat "$fichier_csv"
echo '--xxxxyyyzzqzzyyyxxxx--'
} | /usr/sbin/sendmail -t

Joel