jmail接收邮件出错??急!!
jmail.POP3Class mail = new POP3Class();
ArrayList list = new ArrayList();
mail.Connect(userName,pwd,server,110);//连接POP3服务器,这里的userName,pwd,server都是正确的输入
Console.WriteLine("Count="+mail.Count);//程序可以正确输出结果,
mail.DownloadHeaders();//从此处开始报错:未处理的“System.Runtime.InteropServices.COMException”类型的异常出现在 MailReceiver.exe 中。
其他信息: Connection reset by client
jmail.Message msg=new jmail.Message();
msg=mail.Messages[mail.Count];
Console.WriteLine(msg.Subject);
如果去掉mail.DownloadHeaders();也报相同的错误,我使用过4.2 4.3.0 的jmail都是一样
如果使用4.3.1的jmail连Console.WriteLine("Count="+mail.Count);都会报错:This version has not included this function
请各位大侠多多提点,谢谢!!!
问题点数:40、回复次数:6Top
1 楼dark824113(程序员有苦有甜)回复于 2005-07-19 18:49:32 得分 0
upTop
2 楼dark824113(程序员有苦有甜)回复于 2005-07-19 18:51:14 得分 0
upTop
3 楼where123()回复于 2005-07-19 19:12:01 得分 20
sing System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using jmail;
using System.IO;
namespace Hi_Tech.oa.mail
{
/// <summary>
/// mailin 的摘要说明。
/// </summary>
public class mailin : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
jmail.POP3 mypop3=new jmail.POP3Class();//建立收邮件对象
try
{
mypop3.Connect("honglan1222","zhu4088","pop3.163.com",110);
mypop3.Logging=true;
}
catch(Exception ex)
{
string str="";
str =ex.Message.ToString();
Response.Write(str);
Response.End();
}
int stt,mailNum=1;
string AttName;
jmail.MessageClass Mail=new MessageClass();//建立邮件信息接口
int n = mypop3.Messages.Count;//邮件数目
for(;mailNum<mypop3.Messages.Count;mailNum++)
{
Mail=(MessageClass)mypop3.Messages[mailNum];
Mail.ContentTransferEncoding="base64";
Mail.Encoding="base64";
Mail.Charset="GB2312";
Response.Write(Mail.Subject+"<br>");
Response.Write("<font color='red'>发信人:</font>"+Mail.From.ToString());
}
for(int i=0;i<Mail.Attachments.Count;i++)
{
jmail.Attachment att=Mail.Attachments[i];//建立附件接口
AttName=att.Name;
if((stt=AttName.IndexOf("\""))!=-1)
{AttName=AttName.Substring(0,stt);}
//string filepath = "hhh/"+AttName;//得到文件名路径
string filepath = "/Hi_Tech/oa/bbs/Upload/"+AttName;
string path = Server.MapPath(filepath);
if(File.Exists(Server.MapPath(filepath)))
{
File.Delete(Server.MapPath(filepath));
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
Top
4 楼weixinzhu(我想哭,可是我没有眼泪)回复于 2005-07-19 20:03:23 得分 0
private void RecMail()
{
// string userName=this.txtUsername.Text;
// string passwd=this.Password.Text;
// string popserver=this.txtPopServer.Tex
jmail.POP3Class email=new POP3Class();
jmail.MessageClass msg=new jmail.MessageClass();
email.Connect(userName,passwd,popserver,110);
if (email.Count >0)
{
for(int i=1;i<=email.Count;i++)
{
msg=(jmail.MessageClass)email.Messages[i];
if (this.Status_rec.Items.Count >50)
{
this.Status_rec.Items.RemoveAt(0);
}
this.Status_rec.Items.Add("发送方: "+msg.FromName+" 主题:"+msg.Subject);
if(msg.Attachments.Count >0)
{
for(int j=0;j<msg.Attachments.Count;j++)
{
// this.Status.Items.Add(msg.Attachments[j].Name.ToString());
jmail.AttachmentClass emailAttch=new AttachmentClass();
emailAttch=(jmail.AttachmentClass)msg.Attachments[j];
if(File.Exists(strCrecPath+emailAttch.Name.ToString()))
{
File.Delete(strCrecPath+emailAttch.Name.ToString());
}
emailAttch.SaveToFile(strCrecPath+emailAttch.Name.ToString());
}
}
if (!this.ckBackUp.Checked)
{//删除邮件
email.DeleteSingleMessage(i);
}
}//end for
}//end if
msg.Clear();
msg.Close();
email.Disconnect();
}Top
5 楼dark824113(程序员有苦有甜)回复于 2005-07-19 23:09:22 得分 0
upTop
6 楼darklight2000(黄俊)回复于 2005-07-19 23:13:23 得分 20
问题出在mail.Count上
实际邮件数应该是mail.Count-1
因此msg=mail.Messages[mail.Count];应改为msg=mail.Messages[mail.Count-1];
而且mail.DownloadHeaders();可以不要。Top




