用jmail收取邮件附件的古怪问题
我想做个简易邮件客户端,用System.Net.Mail命名空间下的类发送邮件,可以在网站上或者OE等客户端里正确显示内容。但是,如果用jmail接收,却发现完全无法解析出附件名称和类型,附件名一律是.msg,不过如果改成它们原本的名字,可以发现附件内容实际上已经被正确下载了,因为可以正确打开。我实在不知道为什么,难道是jmail的bug?
下面贴出部分源码,希望各位帮忙:
发送邮件的:
tring FromMail = "tangsiyanking@sina.com";//发件人
string Title = "test"; //邮件主题
string Body = "test"; //邮件主体
string ShowName = "paladintsy";//显示名字
string MailUserName = "tangsiyanking";
string MailPassword = "xxxxxx";//密码就不给了....
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress(FromMail,ShowName,System.Text.Encoding.GetEncoding("GB2312"));
msg.Subject = Title;//邮件标题
msg.Body = Body;//邮件内容
msg.Priority = MailPriority.Normal;//邮件优先级
msg.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312");//标题编码
msg.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");//正文编码
msg.To.Add("seu_tangsiyan@qq.com");
System.Net.Mail.Attachment attTemp = new System.Net.Mail.Attachment("C:\\Documents and Settings\\HellKnight\\My Documents\\My Pictures\\profile.txt");
attTemp.NameEncoding = System.Text.Encoding.GetEncoding("GB2312");//附件名编码
msg.Attachments.Add(attTemp);
.....................................................
接收邮件:
string subject;
string body;
jmail.Message jmsg = new jmail.Message();//生成jmail邮件对象
jmail.POP3 jpop = new jmail.POP3();//生成POP3对象,用于连接服务器
jmail.Attachments atts = new jmail.Attachments();//附件集合对象
jmail.Attachment att = new jmail.Attachment();//附件对象
jpop.Connect("tangsiyanking","xxxxxx","pop3.sina.com.cn",110);//连接服务器,4个参数依次为用户名,密码,服务器地址,端口号(可选,默认就是110)
for (int i = 1; i <= jpop.Count; i++)//如果有邮件就接收
{
jmsg = jpop.Messages[i];//取得第i封邮件,注意这个数组下标从1开始
atts = jmsg.Attachments;//取得邮件的所有附件
subject = jmsg.Subject;//得到邮件标题
body = jmsg.Body;
for (int j = 0; j < atts.Count; j++)
{
att = atts[j];
if (File.Exists("D:\\atts\\" + att.Name))
{
int count = 1;
while (File.Exists("D:\\atts\\" + "(" + count + ")" + att.Name))
{
++count;
}
att.SaveToFile("D:\\atts\\" + "(" + count + ")" +att.Name);
}
else
{
att.SaveToFile("D:\\atts\\" + att.Name);
}
if (j != atts.Count - 1)
attachmentpath += ",";
}
...................................................
主要的就是上面贴出的代码,请大家帮忙看看,什么地方可能出错?
------解决方案--------------------你用的jmail哪个版本?
用其它版