快速业务通道

利用Jmail接收邮件

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-07-03

/**//// <summary>
/// 利用Jmail接收邮件
/// </summary>
private void ReciveByJmail()
{    
    
/**////建立收邮件对象
    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++)                                                       
            {
                
/**////取得一条邮件信息
                mailMessage = popMail.Messages[i];                                                        

                
/**////取得该邮件的附件集合
                atts = mailMessage.Attachments; 
                
                
/**////设置邮件的编码方式                          
                mailMessage.Charset = "GB2312"
                
                
/**////设置邮件的附件编码方式                         
               mailMessage.Encoding = "Base64"
                
                
/**////是否将信头编码成iso-8859-1字符集                        
               mailMessage.ISOEncodeHeaders = false
                
               
/**////邮件的优先级                     
                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 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!请检查邮件服务器的设置是否正确!");
    }
}


    
/**////建立附件集接口
    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++)                                                       
            {
                
/**////取得一条邮件信息
                mailMessage = popMail.Messages[i];                                                        

                
/**////取得该邮件的附件集合
                atts = mailMessage.Attachments; 
                
                
/**////设置邮件的编码方式                          
                mailMessage.Charset = "GB2312"
                
                
/**////设置邮件的附件编码方式                         
               mailMessage.Encoding = "Base64"
                
                
/**////是否将信头编码成iso-8859-1字符集                        
               mailMessage.ISOEncodeHeaders = false
                
               
/**////邮件的优先级                     
                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 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!请检查邮件服务器的设置是否正确!");
    }
}

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号