1.确认sendmail服务on-line
如果sendmail服务已经启动,则下面的命令输出:
# svcs –a | grep sendmail
Online Jul_22 svc:/network/smtp:sendmail
否则,
# svcs –a | grep sendmail
disabled 3:33:43 svc:/network/smtp:sendmail
其中,3:33:43代表了disable的时间。用下面的命令enable sendmail服务:
# svcadm enable sendmail
2.利用sendx发送email
#!/bin/sh#
# Purpose: Demonstrate how to send an email from UNIX using mailx.
############################################################
# Example 1 - Simple:
echo "This is the body."| mailx -s "mailx Test1" jsmith@abc.com
# Example 2 - Using Variables:
SUBJECT="mailx Test2"
EMAIL_ADDRESS="jsmith@abc.com"
BODY="This is the body of the message."
echo "$BODY" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"
# Example 3 - Attached File:
SUBJECT="mailx Test3"
EMAIL_ADDRESS="jsmith@abc.com"
BODY="This is the body of the message."
ATTACHED_FILE="/etc/hosts"
cat "$ATTACHED_FILE" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"
# Example 4 - Attached File to Windows Email:
SUBJECT="mailx Test4"
EMAIL_ADDRESS="jsmith@abc.com"
BODY="This is the body of the message."
ATTACHED_FILE_DIR="/etc/"
ATTACHED_FILE="hosts"
ATTACHED_FILE_AS="hosts.txt"
unix2dos "$ATTACHED_FILE_DIR$ATTACHED_FILE" > /tmp/"$ATTACHED_FILE_AS"
uuencode /tmp/"$ATTACHED_FILE_AS" /tmp/"$ATTACHED_FILE_AS" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"
rm /tmp/"$ATTACHED_FILE_AS"