I am currently working on my own SMTP server and I can successfully send email arounds from various programs and web pages such as Outlook, PHP and Pear Mail.
The next stage I need to do is to try and send an attachment via my SMTP server. I have tried doing a LAN trace of my server while sending an attachment via PHP to another SMTP server and I can see I get the follwing from the client:
DATA fragment, 661 bytes
I’m not sure if this is related to the attachment or not.
If it is, is this just telling the SMTP server how long the file is and then I should just write a base 64 encoded string onto the network stream and write it to a file to be used for sending the email on.
Thanks for any help you can provide.
SMTP has no concept of “attachments” to messages. E-mail attachments are part of the same body of the message that in SMTP is all transmitted between the
DATAcommand and the End-of-DATA indicator (the.“command”). See RFC 5321. Note that there is no way in SMTP to tell the server how much data is going to follow theDATAcommand, though there is a way for the server to give a limit to the size of a message body (and the reply to the End-of-DATA command might be an error response code and a message indicating that too much data was sent.You can use MIME to identify different parts of the body of the message, but the creation and interpretation of the message body are entirely outside the scope of the SMTP server. See RFC 2045 and RFC 2046, and the many other related RFCs that refine the MIME specification (including RFC2184, RFC2231, RFC5335, RFC6532, RFC2646, RFC3798, RFC5147, RFC6657).