邮件操作:POP3协议
获取邮件主题
邮件的主题一般采用Base64编码,例如:Subject: =?gb2312?B?0MLUsbmktb242s2o1qo=?=
其中=?和?=之间的就是邮件主题,前半部分标示了邮件内容原始编码(gb2312),后面的B表示了邮件主题现在的编码
(重要)通知:关于办公区电表改造断电通知(呼叫中心除外)
所以获取正确的邮件主题需要先将主题部分字符串转换成字节码,然后用GB2312编码获取字符串
新员工到岗通知
邮件的主题一般采用Base64编码,例如:Subject: =?gb2312?B?0MLUsbmktb242s2o1qo=?=
其中=?和?=之间的就是邮件主题,前半部分标示了邮件内容原始编码(gb2312),后面的B表示了邮件主题现在的编码
1
//获取邮件主题
2
//正则表达式实现
3
string MailTitle="";
4
//Src仅仅表示邮件的一个部分,其中Subject表示主题部分
5
string Src=
6
"Subject:=?gb2312?B?o6jW2NKqo6nNqNaqo7q52NPasOy5q8f4teex7bjE1Oy2z7XnzajWqg==?=\r\n=?gb2312?B?o6i69L3Q1tDQxLP9zeKjqQ==?=\r\n";
7
string c = @"=\?gb2312\?B\?(.*?)\?=";
8
Regex myReg = new Regex(c, RegexOptions.IgnoreCase);
9
MatchCollection Mt = myReg.Matches(Src);
10
if (Mt != null)
11
{
12
for(int i=0;i<Mt.Count;i++)
13
{
14
MailTitle+=Mt[i].Groups[1].Value;
15
}
16
}
上面这段主题的内容经过下面的解码后是:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
(重要)通知:关于办公区电表改造断电通知(呼叫中心除外)
所以获取正确的邮件主题需要先将主题部分字符串转换成字节码,然后用GB2312编码获取字符串
1
//获取主题中内容字符串方式很多,在此只写一个用正则表达式的简单例子
2
string C="0MLUsbmktb242s2o1qo=";
3
//将主题部分转换成字节数组
4
byte[] B=Convert.FromBase64String(C);
5
//用GB2312格式编码得到原始的主题
6
string SrcString=Encoding.GetEncoding("GB2312").GetString(B));
比如这段主题就是:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
新员工到岗通知