使用linux自带mail命令发送邮件和使用perl的MIME::Lite模块发送邮件

发送文件内容为"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;


转载于:https://my.oschina.net/forrest420/blog/382122

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值