Script que envia email para um Relay sem autenticação.

Publicado por Alessandro Dias 09/04/2007

[ Hits: 6.596 ]

Download envia_email.sh




Script que envia email para um Relay sem autenticação.

O script pode enviar email para 5 destinatários com até 8 arquivos anexados.

Utilizei um relay aberto que tenho no trabalho.

  



Esconder código-fonte

#!/usr/bin/expect -f
# @ Alessandro Dias [18/09/2006]

# envia_email.sh [arg0] [arg1] [arg2] [arg3] [arg4] [arg5] [arg6] [argv7-14] 

# Argumentos:
# 0  - $TO1 - destinatario do email (TO1)
# 1  - $TO2 - copia para o email TO2
# 2  - $TO3 - copia para o email TO3
# 3  - $TO4 - copia para o email TO4
# 4  - $TO5 - copia para o email TO4
# 5  - $SUBJECT - assunto do email
# 6  - $DATA - corpo do email
# 7  - $ATTACH - arquivo anexado
# 8  - $ATTACH2 - arquivo anexado
# 9  - $ATTACH3 - arquivo anexado
# 10 - $ATTACH4 - arquivo anexado
# 11 - $ATTACH5 - arquivo anexado
# 12 - $ATTACH6 - arquivo anexado
# 13 - $ATTACH7 - arquivo anexado
# 14 - $ATTACH8 - arquivo anexado

set RELAY "10\.144\.104\.101"
set TO1 [lindex $argv 0]
set TO2 [lindex $argv 1]
set TO3 [lindex $argv 2]
set TO4 [lindex $argv 3]
set TO5 [lindex $argv 4]
set SUBJECT [lindex $argv 5]
set DATA [lindex $argv 6]
set ATTACH1 [lindex $argv 7]
set ATTACH2 [lindex $argv 8]
set ATTACH3 [lindex $argv 9]
set ATTACH4 [lindex $argv 10]
set ATTACH5 [lindex $argv 11]
set ATTACH6 [lindex $argv 12]
set ATTACH7 [lindex $argv 13]
set ATTACH8 [lindex $argv 14]
set FILENAME1 [exec basename $ATTACH1]
set FILENAME2 [exec basename $ATTACH2]
set FILENAME3 [exec basename $ATTACH3]
set FILENAME4 [exec basename $ATTACH4]
set FILENAME5 [exec basename $ATTACH5]
set FILENAME6 [exec basename $ATTACH6]
set FILENAME7 [exec basename $ATTACH7]
set FILENAME8 [exec basename $ATTACH8]

spawn telnet $RELAY 25
expect "220 dpf.gov.br ESMTP"
send "helo dpf.gov.br\r"
expect "250 canario.dpf.gov.br"
send "mail from\: <[email protected]>\r"
expect "250 Ok"
send "rcpt to\: \<$TO1\>\r"
expect "250 Ok"
send "rcpt to\: \<$TO2\>\r"
expect "250 Ok"
send "rcpt to\: \<$TO3\>\r"
expect "250 Ok"
send "rcpt to\: \<$TO4\>\r"
expect "250 Ok"
send "rcpt to\: \<$TO5\>\r"
expect "250 Ok"
send "data\r"
expect "354 End data with <CR><LF>.<CR><LF>"
send "from\: [email protected]\r"
send "to\: $TO1\r"
send "subject: $SUBJECT\r"
send "Mime-Version: 1.0\r"
send "Content-Type\: multipart\/mixed\; boundary\=\"boundarystring\"\r"
send "\r\--boundarystring\r"
send "Content-Type\: text\/plain\; charset\=US-ASCII \r\r"
send "Backup realizado em [exec date]\r"
send "$DATA\r"
send "\r\--boundarystring\r"
if {$FILENAME1 ne ""} {
send "Content-Type\: application/octet-stream\;name\=\"$FILENAME1\"\r"
send "Content-Transfer-Encoding\: base64\r"
send "Content-Disposition\: attachment\;filename\=\"$FILENAME1\"\r"
send [exec openssl enc -base64 -in $ATTACH1]
send "\r\--boundarystring\r"
}
if {$FILENAME2 ne ""} {
send "Content-Type\: application/octet-stream\;name\=\"$FILENAME2\"\r"
send "Content-Transfer-Encoding\: base64\r"
send "Content-Disposition\: attachment\;filename\=\"$FILENAME2\"\r"
send [exec openssl enc -base64 -in $ATTACH2]
send "\r\--boundarystring\r"
}
if {$FILENAME3 ne ""} {
send "Content-Type\: application/octet-stream\;name\=\"$FILENAME3\"\r"
send "Content-Transfer-Encoding\: base64\r"
send "Content-Disposition\: attachment\;filename\=\"$FILENAME3\"\r"
send [exec openssl enc -base64 -in $ATTACH3]
send "\r\--boundarystring\r"
}
if {$FILENAME4 ne ""} {
send "Content-Type\: application/octet-stream\;name\=\"$FILENAME4\"\r"
send "Content-Transfer-Encoding\: base64\r"
send "Content-Disposition\: attachment\;filename\=\"$FILENAME4\"\r"
send [exec openssl enc -base64 -in $ATTACH4]
send "\r\--boundarystring\r"
}
if {$FILENAME5 ne ""} {
send "Content-Type\: application/octet-stream\;name\=\"$FILENAME5\"\r"
send "Content-Transfer-Encoding\: base64\r"
send "Content-Disposition\: attachment\;filename\=\"$FILENAME5\"\r"
send [exec openssl enc -base64 -in $ATTACH5]
send "\r\--boundarystring\r"
}
if {$FILENAME6 ne ""} {
send "Content-Type\: application/octet-stream\;name\=\"$FILENAME6\"\r"
send "Content-Transfer-Encoding\: base64\r"
send "Content-Disposition\: attachment\;filename\=\"$FILENAME6\"\r"
send [exec openssl enc -base64 -in $ATTACH6]
send "\r\--boundarystring\r"
}
if {$FILENAME7 ne ""} {
send "Content-Type\: application/octet-stream\;name\=\"$FILENAME7\"\r"
send "Content-Transfer-Encoding\: base64\r"
send "Content-Disposition\: attachment\;filename\=\"$FILENAME7\"\r"
send [exec openssl enc -base64 -in $ATTACH7]
send "\r\--boundarystring\r"
}
if {$FILENAME8 ne ""} {
send "Content-Type\: application/octet-stream\;name\=\"$FILENAME8\"\r"
send "Content-Transfer-Encoding\: base64\r"
send "Content-Disposition\: attachment\;filename\=\"$FILENAME8\"\r"
send [exec openssl enc -base64 -in $ATTACH8]
send "\r\--boundarystring\r"
}
send "\r.\r"
expect "250 Ok"
send "quit\r"
expect eof



Scripts recomendados

Checa Host

Pesquisa Binária usando Bash-Shell

Script para adicionar usuarios ftp

Kit de Scripts para Backup (Full + Diferencial + SMBmount + Rede) - Atualizado

Dicionário e tradutor baseado no Michaelis


  

Comentários
[1] Comentário enviado por diaspcf em 07/05/2007 - 15:28h

Caro Usuário,
Tente pegar o script a partir do código fonte, pois parece que o link está quebrado.
Obrigado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts