使用pop3接收邮件时,excel和word格式的附件产生乱码.

时间:2022-12-06 19:03:54
使用pop3接收邮件时,excel和word格式的附件产生乱码.但txt格式的附件正常显示.

13 个解决方案

#1


http://blog.csdn.net/zhangjian01361/articles/1132611.aspx

#2


to 使用pop3接收邮件时,excel和word格式的附件产生乱码.但txt格式的附件正常显示

你怎么接收附件的

#3


A POP3 client in C# .NET for reading and processing emails (including attachments).
ref:
http://www.codeproject.com/cs/internet/despop3client.asp

#4


mark

#5


帮顶

#6


学习

#7


我刚刚解决了,多换几个版本的jmail试下,每次都要重启才能生效

#8


你代码怎么写的。。。一般要编码转换的

#9


代码是这样的,但是excel和word格式不行,txt可以啊

jmail.POP3Class popMail = new POP3Class();//建立收邮件对象
jmail.Message mailMessage;  //建立邮件信息接口
jmail.Attachments atts;//建立附件集接口
jmail.Attachment att;//建立附件接口

try
{
popMail.Connect(TxtPopUser.Text.Trim(),TxtPopPwd.Text.Trim(),TxtPopServer.Text.Trim(),Convert.ToInt32(TxtPopPort.Text.Trim()));

if(0 < popMail.Count)                                                                          //如果收到邮件
{
for(int i=1;i <= popMail.Count;i++)                                                         //根据取到的邮件数量依次取得每封邮件
{
                        //att.ContentType = "application/vnd.ms-excel";
mailMessage = popMail.Messages[i];                                                        //取得一条邮件信息
atts = mailMessage.Attachments;                                                           //取得该邮件的附件集合
                                                                           //设置邮件的编码方式
                        mailMessage.Logging = true;
                        mailMessage.Silent = true;
                        mailMessage.Charset = "GB2312";
                        mailMessage.Encoding = "base64";
                        mailMessage.ContentTransferEncoding = "base64";
                        //mailMessage.Encoding = "Base64";                                                          //设置邮件的附件编码方式
                        //mailMessage.Encoding = "Base64";
                        //mailMessage.ContentType = "application/vnd.ms-excel";
                        //mailMessage.ContentTransferEncoding = "base64";
                        //mailMessage.Encoding = "UTF-32";                                                          //设置邮件的附件编码方式
mailMessage.ISOEncodeHeaders = false;                                                     //是否将信头编码成iso-8859-1字符集
txtpriority.Text = mailMessage.Priority.ToString();                                       //邮件的优先级                 
txtSendMail.Text = mailMessage.From;                                                      //邮件的发送人的信箱地址
txtSender.Text = mailMessage.FromName;                                                    //邮件的发送人
txtSubject.Text = mailMessage.Subject;                                                    //邮件主题
txtBody.Text = mailMessage.Body;                                                          //邮件内容
txtSize.Text = mailMessage.Size.ToString();                                                          //邮件大小

for(int j=0;j<atts.Count;j++)
{
att = atts[j];                                                                        //取得附件
                            string ddddd=att.Data;
                            string ddd = att.ContentType;
                            //att.ContentType = "application/vnd.ms-excel";
string attname = att.Name;                                                            //附件名称

att.SaveToFile("e:\\attFile\\"+attname);                                              //上传到服务器

}

}
panMailInfo.Visible = true;
att = null;
atts = null;
}
else
{
Response.Write("没有新邮件!");
}

popMail.DeleteMessages();
popMail.Disconnect();
popMail = null;
}
catch
{
Response.Write("Warning!请检查邮件服务器的设置是否正确!");
}

#10



mark

#11


jxgz(繼續關注)

#12


我写一个POP3组件,需要的话可以问我要。

#13


http://download.csdn.net/source/161830

#1


http://blog.csdn.net/zhangjian01361/articles/1132611.aspx

#2


to 使用pop3接收邮件时,excel和word格式的附件产生乱码.但txt格式的附件正常显示

你怎么接收附件的

#3


A POP3 client in C# .NET for reading and processing emails (including attachments).
ref:
http://www.codeproject.com/cs/internet/despop3client.asp

#4


mark

#5


帮顶

#6


学习

#7


我刚刚解决了,多换几个版本的jmail试下,每次都要重启才能生效

#8


你代码怎么写的。。。一般要编码转换的

#9


代码是这样的,但是excel和word格式不行,txt可以啊

jmail.POP3Class popMail = new POP3Class();//建立收邮件对象
jmail.Message mailMessage;  //建立邮件信息接口
jmail.Attachments atts;//建立附件集接口
jmail.Attachment att;//建立附件接口

try
{
popMail.Connect(TxtPopUser.Text.Trim(),TxtPopPwd.Text.Trim(),TxtPopServer.Text.Trim(),Convert.ToInt32(TxtPopPort.Text.Trim()));

if(0 < popMail.Count)                                                                          //如果收到邮件
{
for(int i=1;i <= popMail.Count;i++)                                                         //根据取到的邮件数量依次取得每封邮件
{
                        //att.ContentType = "application/vnd.ms-excel";
mailMessage = popMail.Messages[i];                                                        //取得一条邮件信息
atts = mailMessage.Attachments;                                                           //取得该邮件的附件集合
                                                                           //设置邮件的编码方式
                        mailMessage.Logging = true;
                        mailMessage.Silent = true;
                        mailMessage.Charset = "GB2312";
                        mailMessage.Encoding = "base64";
                        mailMessage.ContentTransferEncoding = "base64";
                        //mailMessage.Encoding = "Base64";                                                          //设置邮件的附件编码方式
                        //mailMessage.Encoding = "Base64";
                        //mailMessage.ContentType = "application/vnd.ms-excel";
                        //mailMessage.ContentTransferEncoding = "base64";
                        //mailMessage.Encoding = "UTF-32";                                                          //设置邮件的附件编码方式
mailMessage.ISOEncodeHeaders = false;                                                     //是否将信头编码成iso-8859-1字符集
txtpriority.Text = mailMessage.Priority.ToString();                                       //邮件的优先级                 
txtSendMail.Text = mailMessage.From;                                                      //邮件的发送人的信箱地址
txtSender.Text = mailMessage.FromName;                                                    //邮件的发送人
txtSubject.Text = mailMessage.Subject;                                                    //邮件主题
txtBody.Text = mailMessage.Body;                                                          //邮件内容
txtSize.Text = mailMessage.Size.ToString();                                                          //邮件大小

for(int j=0;j<atts.Count;j++)
{
att = atts[j];                                                                        //取得附件
                            string ddddd=att.Data;
                            string ddd = att.ContentType;
                            //att.ContentType = "application/vnd.ms-excel";
string attname = att.Name;                                                            //附件名称

att.SaveToFile("e:\\attFile\\"+attname);                                              //上传到服务器

}

}
panMailInfo.Visible = true;
att = null;
atts = null;
}
else
{
Response.Write("没有新邮件!");
}

popMail.DeleteMessages();
popMail.Disconnect();
popMail = null;
}
catch
{
Response.Write("Warning!请检查邮件服务器的设置是否正确!");
}

#10



mark

#11


jxgz(繼續關注)

#12


我写一个POP3组件,需要的话可以问我要。

#13


http://download.csdn.net/source/161830