要想各种邮件处理程序能识别我们所写的电子邮件,能从我们所书写的电子邮件中分析和提取出发件人,收件人,邮件主题和邮件内容以及附件等信息,那么我们所写的电子邮件必须要遵循一定的格式要求,正如我们上一篇博客 手工体验smtp和pop3协议 ,我们在发送邮件时有固定的写法。而这种邮件内容的基本格式和具体细节分别是由 RFC822 文档和 MIME 协议定义的。

 

1、RFC822 邮件格式

  英文参考文档如下:https://tools.ietf.org/html/rfc822

  RFC822 文档中定义的文件格式包括两个部分:邮件头和邮件体。在上一篇博客,我们通过SMTP服务发送一封邮件,然后用POP3服务器接收。邮件接收内容如下图红色框所显示:

  

  这上面显示的不全,我这里将其内容整理出来,并在每行左边加上标号:

1  Received: from smtpbg5.qq.com (unknown [ 183.60 . 61.230 ])
         by mx6 (Coremail) with SMTP id OMCowACXv+ssf99ZD5FqAg--.5570S3;
         Thu, 12  Oct 2017  22 : 41 : 48  + 0800  (CST)
2  DKIM-Signature: v= 1 ; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512;
         t= 1507819308 ; bh=N2xK6iU/bt0tcntOdutSQ3tkYXbTtOi08RT+HjuXmBc=;
         h=From:To:Subject:Mime-Version:Content-Type:Content-Transfer-Encoding:Date:Message-ID;
         b=lzBtxAWw0+HB1bGLkkCqlUeU4bvVoMxDp3UZTKq3YCIJt5Ypu4FkE0m5rrrpcxF0D
          W0/PQajrQTughLTmpjoudI5aDWjfrfkOc1Z0+ltaAraoZfdE5HmNQ0hxQstNa+IbjC
          GMVEzCOMikVm5qklyCz/1Lwd5mBJ90YkknS3sL08=
3  X-QQ-FEAT: Gf8h89u9tNwRjwDYIPPhYegibbvTgUmwr4I/ntV6mwr6YOyFiWpUpVj+bCsJz
         tAz24NjMs/p1D8BXG7LYvZRCPMPQV7jdW3AKjTclrSS9xE29fxWsEjYk5QlD1cMIuhHF9Po
         1HMwWKIZX8q6smehIwr+t/du8sprvHVue4ty5KMPeWw967qaAZgta5hcnRtgajhZRcIumVx
         r+K4/nY7I+wwNenOTfHT4Ly4K1Ne+vD7VNJbLHH674HEJ2CsoSEEBW7X/LeeSq6M=
4  X-QQ-SSF: 0001000000000010000000000000007
5  X-HAS-ATTACH: no
6  X-QQ-BUSINESS-ORIGIN: 2
7  X-Originating-IP: 113.57 . 253.69
8  X-QQ-STYLE:
9  X-QQ-mid: webmail4t1507819307t4823829
 
10  From: "=?ISO-8859-1?B?MTEzMjgwMzk1MQ==?="  < 1132803951 @qq .com>
11  To: "=?ISO-8859-1?B?MTgyNzEyNjU3MzI=?="  < 18271265732 @163 .com>
12  Subject: hello world
13  Mime-Version: 1.0
14  Content-Type: multipart/alternative;
         boundary= "----=_NextPart_59DF7F2B_08CB07D0_339F08F2"
15  Content-Transfer-Encoding: 8Bit
16  Date: Thu, 12  Oct 2017  22 : 41 : 47  + 0800
17  X-Priority: 3
18  Message-ID: @qq .com>
19  X-QQ-MIME: TCMime 1.0  by Tencent
20  X-Mailer: QQMail 2 .x
21  X-QQ-Mailer: QQMail 2 .x
22  X-QQ-SENDSIZE: 520
23  Received: from qq.com (unknown [ 10.137 . 130.92 ])
         by smtp.qq.com (ESMTP) with SMTP
         id ; Thu, 12  Oct 2017  22 : 41 : 47  + 0800  (CST)
24  Feedback-ID: webmail:qq.com:bgweb:bgweb4
25  X-CM-TRANSID:OMCowACXv+ssf99ZD5FqAg--.5570S3
26  Authentication-Results: mx6; spf=pass smtp.mail= 1132803951 @qq .com; dki
         m=pass header.i= @qq .com
27  X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73
         VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4RWLvtDUUUU