- m_pImap.Fetch(
- false,
- IMAP_t_SeqSet.Parse("1:*"),
- new IMAP_t_Fetch_i[]{
- new IMAP_t_Fetch_i_Envelope(),
- new IMAP_t_Fetch_i_Flags(),
- new IMAP_t_Fetch_i_InternalDate(),
- new IMAP_t_Fetch_i_Rfc822Size(),
- new IMAP_t_Fetch_i_Uid(),
- new IMAP_t_Fetch_i_Rfc822()
- },
- this.m_pImap_Fetch_MessageItems_UntaggedResponse
上面的代码是直接收取邮件,包括头字段和邮件正文。
- new IMAP_t_Fetch_i_Rfc822()
注意,这句话是表示接收邮件的正文,而我经过测试,发现这段代码在接收yahoo邮箱的时候,邮件不能收取完全,因此在收取其他邮箱服务器的时候,可以采用上面的代码进行整体收件。
因此可以改成下面的这段代码
- if(ip=="apple.imap.mail.yahoo.com")
- {
-
- m_pImap.Fetch(
- true,
- IMAP_t_SeqSet.Parse("1:*"),
- new IMAP_t_Fetch_i[]{
- new IMAP_t_Fetch_i_Envelope(),
- new IMAP_t_Fetch_i_Flags(),
- new IMAP_t_Fetch_i_InternalDate(),
- new IMAP_t_Fetch_i_Rfc822Size(),
- new IMAP_t_Fetch_i_Uid(),
-
- },
- this.m_pImap_Fetch_MessageItems_UntaggedResponseyahoo
- );
这里实际上就没有采用直接收取正文的方式,实际上,这里只是收取了头字段。那么应该在其他地方继续写收件的代码。
- private void LoadMessage(long uid)
- {
- this.Cursor = Cursors.WaitCursor;
- try{
-
- m_pImap.Fetch(
- true,
- IMAP_t_SeqSet.Parse(uid.ToString()),
- new IMAP_t_Fetch_i[]{
- new IMAP_t_Fetch_i_Rfc822()
- },
- this.m_pImap_Fetch_Message_UntaggedResponse
- );
- }
- catch(Exception x){
- MessageBox.Show(this,"Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
- }
- this.Cursor = Cursors.Default;
- }
-
- private void m_pImap_Fetch_Message_UntaggedResponse(object sender,EventArgs<IMAP_r_u> e)
- {
-
-
- try{
- if(e.Value is IMAP_r_u_Fetch){
- IMAP_r_u_Fetch fetchResp = (IMAP_r_u_Fetch)e.Value;
-
- this.BeginInvoke(new MethodInvoker(delegate(){
- try{
- fetchResp.Rfc822.Stream.Position = 0;
- Mail_Message mime = Mail_Message.ParseFromStream(fetchResp.Rfc822.Stream);
- fetchResp.Rfc822.Stream.Dispose();
-
-
-
-
-
- foreach(MIME_Entity entity in mime.Attachments){
-
- if(entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null){
-
- }
- else{
-
- }
-
-
-
- }
-
- if(mime.BodyText != null){
-
- }
-
- try
- {
-
- str stringhandle=new str();
- string title=mime.From.ToString()+"#"+stringhandle.strlen(mime.Subject.ToString(),20)+"#"+mime.Date.ToString("yyyy年MM月dd日 HH时mm分")+"#"+(mime.BodyText.Length / (decimal)1000).ToString("f2") + " kb#";
- title=FilterSpecial(title);
- cstring mystring=new cstring();
- title=mystring.ENCODE(title);
- title+=".eml";
-
- string filepro=Application.StartupPath+"\\data\\"+thisuser+"\\"+global_user+"\\"+folder+"\\"+title;
- FileStream fs = new FileStream(filepro, FileMode.Create);
- StreamWriter sw = new StreamWriter(fs);
-
- sw.Write(mime);
-
- sw.Flush();
-
- sw.Close();
- fs.Close();
- }
- catch(Exception x)
- {
-
- }
-
- }
- catch(Exception x){
- MessageBox.Show("Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
- }
- }));
- }
- }
- catch(Exception x){
- MessageBox.Show("Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
- }
- }

也就是说,收取邮件头和邮件正文分开,这样就能收取包括yahoo在内的所有邮箱。代码是直接从我的工程文件里面拷出来的,作为参考,不能直接使用,但是保证是一定可以用的,更多问题可以联系我。
邮件收取客户端LumiSoft类库接收yahoo邮件的问题。
原文:http://www.cnblogs.com/waw/p/6370880.html