Linux SHELL scripts send mail

xiaoxiao2021-03-06  52

#! / bin / sh

function echo_help () {? echo "Usage:"? echo "sh mailto.sh -to mailaddr -file messagefilename [-from frommailaddr] [-subject mailsubject] [-fname showname] [-tname toshowname]"}

Email = "to@toaddress.com" emailname = "test mail" messagebody = "tmp.tmp" from = "from@fromaddress.com" fromname = "mailreport" Subject = "mail report"

Until [$ # -eq 0] do? TMPV = $ 1

? IF [$ TMPV = "-from"]; then ?? shift ?? TMPV = $ 1? from = $ TMPV? ELIF [$ TMPV = "-to"]; Then ?? shift ?? TMPV = $ 1 ?? Email = $ TMPV? ELIF [$ TMPV = "-subject"]; then ?? shift ?? TMPV = $ 1? subject = $ TMPV? ELIF [$ TMPV = "-file"]; THEN? Shift ?? TMPV = $ 1 ?? messagebody = $ TMPV? ELIF [$ TMPV = "-fname"]; then ?? Shift ?? TMPV = $ 1 ?? fromname = $ TMPV? ELIF [$ TMPV = "-tname"]; then ?? Shift ?? TMPV = $ 1 ?? emailname = $ TMPV? ELIF [$ TMPV = "--help" -o $ TMPV = "-h"]; then ?? echo_help ?? EXIT 1? FI

? shiftdone

IF! Test -f $ {messagebody}; then? echo "$ {messagebody} NOT EXISTS!"? echo_help? EXIT 2FI

Echo "Begin Send ..."

Echo -e "to: /" $ {emailname} / "<$ {}> / nsubject: $ {surbject} / nsubject: $ {Subject} / n / n`cat $ {MessageBody} `" | / usr / sbin / sendmail -t

Echo "Send Ok."

转载请注明原文地址:https://www.9cbs.com/read-118311.html

New Post(0)