不是那个意思就是如下的收到的一封邮件,怎么判断出哪些是邮件内容,哪些是附件等等
要是单看这封邮件我也可以知道MessageId下面行开始就是内容,但是每封邮件是不完全相同的,我想知道什么算法对任意邮件都适用+OK 1229 octetsReceived: from localhost (localhost [127.0.0.1]) by bjmx6.163.net (Postfix) with SMTP id 98B241D2366C4 for <[email protected]>; Wed, 24 Sep 2003 08:51:42 +0800 (CST)Received: from smtp015.mail.yahoo.com (unknown [216.136.173.59]) by bjmx6 (Coremail) with SMTP id TQ0AAJzqcD8qAK07.1 for <[email protected]>; Wed, 24 Sep 2003 08:51:42 +0800 (CST)X-Originating-IP: [216.136.173.59]Received: from unknown (HELO mayue) ([email protected] with login) by smtp.mail.vip.sc5.yahoo.com with SMTP; 24 Sep 2003 00:51:39 -0000From: "Mayue" <[email protected]>To: [email protected] <[email protected]>Cc: [email protected] <[email protected]>Subject: ggggggggggX-mailer: Foxmail 4.2 [cn]Mime-Version: 1.0Content-Type: text/plain; charset="GB2312"Content-Transfer-Encoding: quoted-printableDate: Wed, 24 Sep 2003 8:50:31 +0800Message-Id: <[email protected]>
aaamayue=A3=AC=C4=FA=BA=C3=A3=A1
=09 sdgdfg
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=D6=C2=C0=F1=A3=A1 =09=09=09=09
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1Mayue=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1aaamayue@yahoo.com.cn=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A12003-09-24
要是单看这封邮件我也可以知道MessageId下面行开始就是内容,但是每封邮件是不完全相同的,我想知道什么算法对任意邮件都适用+OK 1229 octetsReceived: from localhost (localhost [127.0.0.1]) by bjmx6.163.net (Postfix) with SMTP id 98B241D2366C4 for <[email protected]>; Wed, 24 Sep 2003 08:51:42 +0800 (CST)Received: from smtp015.mail.yahoo.com (unknown [216.136.173.59]) by bjmx6 (Coremail) with SMTP id TQ0AAJzqcD8qAK07.1 for <[email protected]>; Wed, 24 Sep 2003 08:51:42 +0800 (CST)X-Originating-IP: [216.136.173.59]Received: from unknown (HELO mayue) ([email protected] with login) by smtp.mail.vip.sc5.yahoo.com with SMTP; 24 Sep 2003 00:51:39 -0000From: "Mayue" <[email protected]>To: [email protected] <[email protected]>Cc: [email protected] <[email protected]>Subject: ggggggggggX-mailer: Foxmail 4.2 [cn]Mime-Version: 1.0Content-Type: text/plain; charset="GB2312"Content-Transfer-Encoding: quoted-printableDate: Wed, 24 Sep 2003 8:50:31 +0800Message-Id: <[email protected]>
aaamayue=A3=AC=C4=FA=BA=C3=A3=A1
=09 sdgdfg
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=D6=C2=C0=F1=A3=A1 =09=09=09=09
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1Mayue=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1aaamayue@yahoo.com.cn=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A12003-09-24
下面是我用jmail组件做的邮件接收程序的一部分,是一些描述性的语句,说明一些关键的东西。
首先确保安装了jmail,其次在项目的引用中添加jmail组件. Imports jmail//在页面中引入jmail//在函数中使用以下语句
Dim straccount As String//用户名
Dim strpasswd As String//密码
Dim strserver As String//邮件服务器 dim pop3 as jmail.POP3
POP3.Connect(straccount, strpasswd, strserver)//建立连结 pop3.count//邮件总数 dim msg as jmail.message
msg=POP3.Messages.item(i)//取出第i封邮件
msg.fromname//发件人姓名
msg.from//发件人信箱
msg.subject//邮件主题
msg.size//邮件大小
msg.body//邮件正文
等等。 以后的工作就是组织格式,查看邮件的方式等。可自定义!
有问题再联系!
如果使用附件,请查看example
本来是想自己写代码收发邮件的,搞了几天还不行
我试试这个组件
成功了就解贴哪位知道RETR返回字符串怎么解析,我还是希望知道
分不够可以另开贴给分
还是用不明白
疯了发送邮件怎么用?最好C#代码的
Message的Send方法他说免费版的每个这个函数,更疯了
http://www.chinabs.net/aspnet/default.asp?infoid=50
http://www.chinabs.net/aspnet/default.asp?infoid=67
都是c#版的!
http://asp3.6to23.com/yshgfly/showwenzh.asp?id=79
那些例子都写的太简单了
收邮件那个认为空就是开始邮件内容了
实际返回的字符串很复杂的(可以看看Foxmail的邮件原始信息)
而且也没有怎么得到和解析附件有没有详细些的,谢谢了
这有好几篇文章。
他讲的是用easymail处理Exchange邮件。和jmail很类似。你可以参照一下。
我用jmail做的收邮件的没问题。只是没做附件那部分。也没做发邮件。
我可以研究一下,之后给你答复!
int EncodeBase64(const unsigned char* pSrc, char* pDst, int nSrcLen, int nMaxLineLen)
{
unsigned char c1, c2, c3; // 输入缓冲区读出3个字节
int nDstLen = 0; // 输出的字符计数
int nLineLen = 0; // 输出的行长度计数
int nDiv = nSrcLen / 3; // 输入数据长度除以3得到的倍数
int nMod = nSrcLen % 3; // 输入数据长度除以3得到的余数
// 每次取3个字节,编码成4个字符
for (int i = 0; i < nDiv; i ++)
{
// 取3个字节
c1 = *pSrc++;
c2 = *pSrc++;
c3 = *pSrc++;
// 编码成4个字符
*pDst++ = EnBase64Tab[c1 >> 2];
*pDst++ = EnBase64Tab[((c1 << 4) | (c2 >> 4)) & 0x3f];
*pDst++ = EnBase64Tab[((c2 << 2) | (c3 >> 6)) & 0x3f];
*pDst++ = EnBase64Tab[c3 & 0x3f];
nLineLen += 4;
nDstLen += 4;
// 输出换行?
if (nLineLen > nMaxLineLen - 4)
{
*pDst++ = '\r';
*pDst++ = '\n';
nLineLen = 0;
nDstLen += 2;
}
}
// 编码余下的字节
if (nMod == 1)
{
c1 = *pSrc++;
*pDst++ = EnBase64Tab[(c1 & 0xfc) >> 2];
*pDst++ = EnBase64Tab[((c1 & 0x03) << 4)];
*pDst++ = '=';
*pDst++ = '=';
nLineLen += 4;
nDstLen += 4;
}
else if (nMod == 2)
{
c1 = *pSrc++;
c2 = *pSrc++;
*pDst++ = EnBase64Tab[(c1 & 0xfc) >> 2];
*pDst++ = EnBase64Tab[((c1 & 0x03) << 4) | ((c2 & 0xf0) >> 4)];
*pDst++ = EnBase64Tab[((c2 & 0x0f) << 2)];
*pDst++ = '=';
nDstLen += 4;
}
// 输出加个结束符
*pDst = '\0';
return nDstLen;
}Base64解码方法中,最简单的也是查表法:将64个可打印字符的值作为索引,查表得到的值(范围为0-63)依次连起来,拼凑成字节形式输出,就得到解码结果。 const char DeBase64Tab[] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62, // '+'
0, 0, 0,
63, // '/'
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // '0'-'9'
0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // 'A'-'Z'
0, 0, 0, 0, 0, 0,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // 'a'-'z'
};
int DecodeBase64(const char* pSrc, unsigned char* pDst, int nSrcLen)
{
int nDstLen; // 输出的字符计数
int nValue; // 解码用到的长整数
int i;
i = 0;
nDstLen = 0;
// 取4个字符,解码到一个长整数,再经过移位得到3个字节
while (i < nSrcLen)
{
if (*pSrc != '\r' && *pSrc!='\n')
{
nValue = DeBase64Tab[*pSrc++] << 18;
nValue += DeBase64Tab[*pSrc++] << 12;
*pDst++ = (nValue & 0x00ff0000) >> 16;
nDstLen++;
if (*pSrc != '=')
{
nValue += DeBase64Tab[*pSrc++] << 6;
*pDst++ = (nValue & 0x0000ff00) >> 8;
nDstLen++;
if (*pSrc != '=')
{
nValue += DeBase64Tab[*pSrc++];
*pDst++ =nValue & 0x000000ff;
nDstLen++;
}
}
i += 4;
}
else // 回车换行,跳过
{
pSrc++;
i++;
}
}
// 输出加个结束符
*pDst = '\0';
return nDstLen;
}
很简单,可是后来我发现还有更简单的就是convert.tobase64....真是气死我了
Content-Type: text/plain;
charset="GB2312"
以上字样表示是text文本,使用gb2312的字符集(注意格式,一定要换行,第二行一定要有{TAB}
Content-Transfer-Encoding: quoted-printable
这个是另外一行,表示以下文本的编码格式,一般会用base64。
剩下的问题就是还原解码了,通常情况是先将文本decode为字节流,再根据字符集将字节流还原为可读文本。
对于Content-Type还有别的,比如application/ms-word之类的,这些都是可以在iis中找到一注册mime类型
看邮件里有
Mime-Version: 1.0
Content-Type: text/plain;说明这是mime 编码的邮件,而且不带附件,带附件好象是 multiple/mixed,e文可能打错了,你可以看看关于mime的RFC 1341和pop3的RFC 1939文档
你这个邮件没附件,所以接下来就是正文了
2。关于base64编码
.net里有convert.tobase64code
不过先要寸为一个byte数组