1

I would like to send an email using ESMTP protocol and attach a file to the email.

I have no errors when sending regular email, I only have problem with attachments.

Here's what I use for sending a regular email (and it works):

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: <myusername@interia.pl>
250 2.1.0 Ok
RCPT TO: <test1@gmail.com>
250 2.1.5 Ok
RCPT TO: <test2@interia.pl>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
From: fakeemail@wp.pl
Subject: msg subject

msg body

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

Then, I wanted to send the image as the attachment:

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: <myusername@interia.pl>
250 2.1.0 Ok
RCPT TO: <test1@gmail.com>
250 2.1.5 Ok
RCPT TO: <test2@interia.pl>
250 2.1.5 Ok
DATA
To: everyone@example.com
From: TillLindemann@Rammstein.de
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

The image is received by the SMTP server, but can not be opened.

What am I doing wrong?

closed as off-topic by Spooler, Jim B, Ward, Esa Jokinen, mdpc Apr 27 '17 at 23:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – Spooler, Jim B, Ward, Esa Jokinen
If this question can be reworded to fit the rules in the help center, please edit the question.

6

You're missing the minimum single blank line between the headers and the message body.

And also the blank lines that are required to separate the message parts. From the RFC

 From: Nathaniel Borenstein <nsb@bellcore.com> 
 To:  Ned Freed <ned@innosoft.com> 
 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.
  • OK, but where exactly? I started modyfing it but now I even not getting the attachment. – mazix Mar 24 '17 at 14:22
  • 1
    The RFC is pretty detailed. – Gerald Schneider Mar 24 '17 at 14:24
  • Just another very silly question, I hope you will be able to answer this. I know how to send images, text files, but how about videos? Can I just simply open a video file in binary mode, convert it to base64 and send like I sent the image? Thank you. – mazix Mar 24 '17 at 18:38
  • Yes, base-64 encode, set the correct content-format and keep in mind that most mail servers still enforce maximum message sizes and base-64 encoding increases the size of the original file by up to 15-25% – HBruijn Mar 24 '17 at 20:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.