发送文件内容为"hello",标题为“Hello world”,附件为tt,到123456@163.com 邮箱
echo "hello " | mail -s "Hello world" -a tt 123456@163.com
===================
使用perl的MIME::Lite模块发送邮件
============================
cat sendMonitorEmail.sh
base_dir=/mic/abc/scripts/someMonitor
sendFile=$base_dir/offsetDiff
subject="Monitor-Kafka-Offset"`date +%Y%m%d`
to=abc@163.com
if [ -f $sendFile ];
then
echo "send email to $to"
/bin/sh /mic/abc/scripts/someMonitor/startSendMail.sh $sendFile $subject $to
else
echo "no result to send mail"
fi
============================
cat startSendMail.sh
file=$1
title=$2
maillist=$3
content=`cat $file`
if [ "$file"x = "--help"x ]; then
echo "Three params,first:filepath;second mail subject; third:receiver list,separate with ',' ;"
exit 0
fi
echo "send mail start ..."
/usr/bin/perl /mic/abc/scripts/someMonitor/mail.pl $file $title $maillist "$content"
echo "send mail end ..."
============================
cat mail.pl
#use strict;
use warnings;
use MIME::Lite;
my $file=shift;
my $title=shift;
my $maillist=shift;
my $message=shift;
my $msg = MIME::Lite->new(
From => 'ds_my@dena.jp',
To => "$maillist",
Subject => "$title",
Type => 'TEXT',
Data => "$message"
);
#send attach
# $msg->attach(
# Type => 'AUTO',
# Path => "$file",
#);
$msg->send;