Envie o anexo para o id do gmail a partir do shell script

2

Eu tenho um script de shell que gera relatórios. Usando crontab eu corro o script todos os dias às 1000 horas.

Quero enviar esse relatório para o meu ID do Gmail como anexo.

Eu tentei usar o mutt, mas não funciona para mim.

Por favor, você poderia me guiar através disso?

Depois de instalar o sendEmail, quando tento enviar o e-mail, estou recebendo as seguintes informações

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.

Eu fiz um yum instalar em perl-Net-SSLeay perl-Net-SMTP-SSL e este é o resultado.

[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

O problema ainda persiste e estou usando o Fedora 19.

    
por debal 14.09.2013 / 10:16

1 resposta

3

Você pode usar o sendEmail

Sobre o SendEmail

SendEmail is a lightweight, command line SMTP email client. If you have the need to send email from a command line, this free program is perfect: simple to use and feature rich. It was designed to be used in bash scripts, batch files, Perl programs and web sites, but is quite adaptable and will likely meet your requirements. SendEmail is written in Perl and is unique in that it requires NO MODULES. It has an intuitive and flexible set of command-line options, making it very easy to learn and use. SendEmail is licensed under the GNU GPL, either version 2 of the License or (at your option) any later version. [Supported Platforms: Linux, BSD, OS X, Windows 98, Windows NT, Windows 2000, & Windows XP]

Seguindo o script eu usei para instalar o sendEmail e enviar e-mail para o gmail id no CentOS / RHEL

#!/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}"

Você pode usar a opção -a para o anexo de arquivo no comando sendEmail

    
por 14.09.2013 / 10:58