Enviando um email com um anexo usando telnet e protocolo ESMTP [closed]

1

Eu gostaria de enviar um e-mail usando o protocolo ESMTP e anexar um arquivo ao e-mail.

Não tenho erros ao enviar e-mails regulares, só tenho problemas com anexos.

Aqui está o que eu uso para enviar um email regular (e funciona):

telnet interia.pl 587
Trying 217.74.65.23...
Connected to interia.pl.
Escape character is '^]'.
220 ESMTP INTERIA.PL
HELO itsme
250 poczta.interia.pl
AUTH LOGIN
334 VXNlcm5hbWU6
myusernameinbase64
334 UGFzc3dvcmQ6
mypasswordinbase64
235 2.7.0 Authentication successful
MAIL FROM: <[email protected]>
250 2.1.0 Ok
RCPT TO: <[email protected]>
250 2.1.5 Ok
RCPT TO: <[email protected]>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
From: [email protected]
Subject: msg subject

msg body

.
250 OK. ID: cbf07b124a2fe43b
QUIT
221 2.0.0 Bye
Connection closed by foreign host.

Então, eu queria enviar a imagem como anexo:

telnet interia.pl 587
Trying 217.74.65.23...
Connected to interia.pl.
Escape character is '^]'.
220 ESMTP INTERIA.PL
HELO itsme
AUTH LOGIN
334 VXNlcm5hbWU6
myusernameinbase64
334 UGFzc3dvcmQ6
mypasswordinbase64
235 2.7.0 Authentication successful
MAIL FROM: <[email protected]>
250 2.1.0 Ok
RCPT TO: <[email protected]>
250 2.1.5 Ok
RCPT TO: <[email protected]>
250 2.1.5 Ok
DATA
To: [email protected]
From: [email protected]
MIME-Version: 1.0
Subject: IMG sending test
Content-Type: multipart/mixed; boundary=sep
--sep
msg body
--sep
Content--Type: application/octet-stream; name=\"image.png\"
Content-Disposition: attachment; filename=\"image.png\"
Content-Transfer-Encoding: base64


jEZxHEdKRTIKpRyG4SAIAxXL1UI57xcH3R/F+JMQmxPny2Qs8tuXypnUL8kbFo/3
LAAAAAAAAMA/jBCilNrZ2bmXrY9hYZk83LlUny3LymQy41yLfwJjjDE28+GFQmGO
F/P/uOuGxNTxaSa5dUzKivMEQsjy8nKj0djY2CgWi+fn57ce4nDOa2sr8subbviC
FDZyYnXVf8xczlzBXI9Rj7keczlzp6fVaJ1orROdxCMlVSijYaf19efpR/r9bbVW
5pxPWdvkUu+0xqkWdB8JAAAAAAAAAFIihMyrDggAAH8PpTSbze7v76+vr5dKpWaz
efP/MBzXdSuVimVZR0fvh9/eJUkSah3OenqTFeJ5XqVWqVQqppMmAAAAAAAAAAAA
ANwP5tv5vb29Wq22trbWbDallNcNdizL4pxXq9VSqRQEQfr2hdcxgeuml6KFHCIA
AAAAAAAAAACA+4VSalnW4eFhq9Wq1+vD4XDc8nHCL6MJuimJikbWAAAAAElFTkSu
QmCC
...
--sep--
.
QUIT

A imagem é recebida pelo servidor SMTP, mas não pode ser aberta.

O que estou fazendo de errado?

    
por mazix 24.03.2017 / 15:07

1 resposta

6

Você está perdendo a linha mínima em branco entre os cabeçalhos e o corpo da mensagem.

E também as linhas em branco necessárias para separar as partes da mensagem. Do RFC

 From: Nathaniel Borenstein <[email protected]> 
 To:  Ned Freed <[email protected]> 
 Subject: Sample message 
 MIME-Version: 1.0 
 Content-type: multipart/mixed; boundary="simple boundary" 

 This is the preamble.  It is to be ignored, though it 
 is a handy place for mail composers to include an 
 explanatory note to non-MIME compliant readers. 
 --simple boundary 

 This is implicitly typed plain ASCII text. 
 It does NOT end with a linebreak. 
 --simple boundary 
 Content-type: text/plain; charset=us-ascii 

 This is explicitly typed plain ASCII text. 
 It DOES end with a linebreak. 

 --simple boundary-- 
 This is the epilogue.  It is also to be ignored.
    
por 24.03.2017 / 15:14