我想使用 ESMTP 协议发送一封电子邮件并将一个文件附加到电子邮件中。
我发送常规电子邮件时没有遇到任何错误,只有附件有问题。
以下是我发送常规电子邮件的方法(并且有效):
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.
然后,我想将图像作为附件发送:
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
图像已被 SMTP 服务器接收到,但无法打开。
我究竟做错了什么?
答案1
缺少标题和邮件正文之间的最小单空白行。
还有分隔消息部分所需的空行。来自 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.