我有一个生成报告的 shell 脚本。我使用 crontab 每天 1000 点运行该凭证。
我想将该报告作为附件邮寄到我的 Gmail ID。
我尝试过使用 mutt 但它对我不起作用。
安装 sendEmail 后,当我尝试发送邮件时,我收到以下信息
Sep 14 15:15:37 debal sendEmail[3671]: DEBUG => Connecting to smtp.gmail.com:587
Sep 14 15:15:38 debal sendEmail[3671]: DEBUG => My IP address is: 192.168.2.103
Sep 14 15:15:38 debal sendEmail[3671]: SUCCESS => Received: 220 mx.google.com ESMTP uw6sm17314211pbc.8 - gsmtp
Sep 14 15:15:38 debal sendEmail[3671]: INFO => Sending: EHLO debal
Sep 14 15:15:38 debal sendEmail[3671]: SUCCESS => Received: 250-mx.google.com at your service, [180.151.208.181], 250-SIZE 35882577, 250-8BITMIME, 250-STARTTLS, 250-ENHANCEDSTATUSCODES, 250 CHUNKING
Sep 14 15:15:38 debal sendEmail[3671]: INFO => Sending: STARTTLS
Sep 14 15:15:38 debal sendEmail[3671]: SUCCESS => Received: 220 2.0.0 Ready to start TLS
*******************************************************************
Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
together with SSL_ca_file|SSL_ca_path for verification.
If you really don't want to verify the certificate and keep the
connection open to Man-In-The-Middle attacks please set
SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
at /usr/local/bin/sendEmail line 1906.
invalid SSL_version specified at /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm line 414.
我在 perl-Net-SSLeay perl-Net-SMTP-SSL 上进行了 yum 安装,这就是结果。
[root@debal ~]# yum install perl-Net-SSLeay perl-Net-SMTP-SSL
Loaded plugins: langpacks, refresh-packagekit
Package perl-Net-SSLeay-1.54-1.fc19.x86_64 already installed and latest version
Package perl-Net-SMTP-SSL-1.01-13.fc19.noarch already installed and latest version
Nothing to do
问题仍然存在,我使用的是 Fedora 19。
答案1
您可以使用发电子邮件
关于发送电子邮件
SendEmail 是一个轻量级的命令行 SMTP 电子邮件客户端。如果您需要从命令行发送电子邮件,这个免费程序是完美的:使用简单且功能丰富。它被设计用于 bash 脚本、批处理文件、Perl 程序和网站,但适应性很强,很可能满足您的要求。 SendEmail 是用 Perl 编写的,其独特之处在于它不需要任何模块。它具有一组直观且灵活的命令行选项,使其非常易于学习和使用。 SendEmail 根据 GNU GPL 获得许可,无论是许可证的第 2 版还是(由您选择)任何更高版本。 [支持的平台:Linux、BSD、OS X、Windows 98、Windows NT、Windows 2000 和 Windows XP]
以下脚本我用来在 CentOS/RHEL 中安装 sendEmail 并将邮件发送到 gmail id
#!/usr/bin/env bash
# Define sender's detail email ID
From_Mail="[email protected]"
# Sender's Username and password account for sending mail
Sndr_Uname="${From_Mail}"
Sndr_Passwd="your_password"
# Define recepient's email ID
To_Mail="[email protected]"
# Define CC to (Note: for multiple CC use ,(comma) as seperator )
# CC_TO="[email protected]"
# Define mail server for sending mail [ IP:PORT or HOSTNAME:PORT ]
RELAY_SERVER="smtp.gmail.com:587"
# Subject
Subject="Test Mail using SendEmail"
# sendEmail download link
download_sendEmail="http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz"
# Mail Body
MSG() {
cat <<_EOF
Dear Sir,
Please find the attachment of PDF File
_EOF
}
# store loggin information in below log file
Log_File="/var/log/sendmail.log"
# check sendmail dir exists or not if not check create it
Log_dir="$(dirname ${Log_File})"
if [ ! -d "${Log_dir}" ]; then
mkdir "${Log_dir}"
fi
check_sendmail() {
if [ ! -x "/usr/bin/sendEmail" ]; then
echo "sendEmail not installed"
echo "Installing sendEmail..."
sleep 1s
wget -cnd "${download_sendEmail}" -O /tmp/sendemail.tar.gz >/dev/null 2>&1
tar -xzf /tmp/sendemail.tar.gz --wildcards *sendEmail
install --mode=744 sendEmail*/sendEmail /usr/bin/
yum install perl-Net-SSLeay perl-Net-SMTP-SSL -y
fi
}
check_sendmail
/usr/bin/sendEmail -v -f ${From_Mail} \
-t ${To_Mail} -u "${Subject}" \
-m `MSG` \
-xu "${Sndr_Uname}" \
-xp "${Sndr_Passwd}" \
-o tls=auto \
-s "${RELAY_SERVER}" \
-cc "${CC_TO}" \
-l "${Log_File}"
您可以使用命令-a
的文件附件选项sendEmail