惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
About on SuperTechFans
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Help Net Security
Help Net Security
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
O
OpenAI News
美团技术团队
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
Cyberwarzone
Cyberwarzone
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google Online Security Blog
Google Online Security Blog
T
Tenable Blog
S
Security Affairs
博客园_首页
S
Schneier on Security
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
Spread Privacy
Spread Privacy
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
TaoSecurity Blog
TaoSecurity Blog
博客园 - 聂微东
Vercel News
Vercel News
M
MIT News - Artificial intelligence
T
Troy Hunt's Blog
B
Blog
MongoDB | Blog
MongoDB | Blog
Martin Fowler
Martin Fowler
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 最新话题
D
DataBreaches.Net
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - Franky
W
WeLiveSecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Fortinet All Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Check Point Blog
H
Hacker News: Front Page

博客园 - 冷火

Lucene.Net学习 Argotic Syndication Framework生成RSS - 冷火 Confirm GridView Deletes with the ModalPopupExtender 如何在C#中实现图片缩放 [ASP.NET] 限制上传文件类型的两种方法 asp.net采集 在C#怎用一条正则表达式验证用逗号隔开的email地址 dhtmlXTreeprofessional asp.net导出xml文件 - 冷火 - 博客园 DateDiff Datagridview下一行下一行 GridView控件修改、删除示例(修改含有DropDownList控件) - 冷火 - 博客园 局域网QQ第三版(V1.4) asp.net+JSON+AJAX(基于prototype1.4)做无刷新的2级DropDownList - 冷火 - 博客园 非常好的菜单效果(Accordion风格) 静功解决失眠的问题 ASP.NET中文验证码详解 log4net Config Examples 对XAML进行编辑的辅助类(XamlHelper)
关于LumiSoft.Net.POP3.Client接收邮件例子(包括附件)
冷火 · 2009-07-06 · via 博客园 - 冷火

 LumiSoftReceive.aspx.cs

using System;using System.Collections.Generic;

using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LumiSoft.Net.POP3.Client;
using LumiSoft.Net.Mime;

public partial class LumiSoftReceive : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        receivemail();
    }
    private void receivemail()
    {
        string strHost;
        int intPort;
        string strlogin;
        string strPassword;
        strHost = "pop.sina.com.cn";
        intPort = 110;
        strlogin = "账户";
        strPassword = "密码";
        bool pop3UseSsl = false;
        List<string> gotEmailIds = new List<string>();

        List<Mime> result = new List<Mime>();

        //Response.Write(Count.ToString());
        DataTable mailTable = new DataTable("mail");
        mailTable.Columns.Add(new DataColumn("MessageID", typeof(string)));
        mailTable.Columns.Add(new DataColumn("Keywords", typeof(string)));
        mailTable.Columns.Add(new DataColumn("Title", typeof(string)));
        mailTable.Columns.Add(new DataColumn("frommail", typeof(string)));
        mailTable.Columns.Add(new DataColumn("tomail", typeof(string)));
        mailTable.Columns.Add(new DataColumn("senddate", typeof(string)));
        mailTable.Columns.Add(new DataColumn("numbers", typeof(string)));
        mailTable.Columns.Add(new DataColumn("content", typeof(string)));
        mailTable.Columns.Add(new DataColumn("Attacht", typeof(string)));

        using (LumiSoft.Net.POP3.Client.POP3_Client pop3 = new POP3_Client())
        {
            try
            {
                //与Pop3服务器建立连接
                pop3.Connect(strHost, intPort, pop3UseSsl);
                //验证身份
                pop3.Authenticate(strlogin, strPassword, false);
                //获取邮件信息列表
                POP3_ClientMessageCollection infos = pop3.Messages;
                foreach (POP3_ClientMessage info in infos)
                {
                    //每封Email会有一个在Pop3服务器范围内唯一的Id,检查这个Id是否存在就可以知道以前有没有接收过这封邮件
                    if (gotEmailIds.Contains(info.UID))
                        continue;
                    //获取这封邮件的内容
                    byte[] bytes = info.MessageToByte();
                    //记录这封邮件的Id
                    gotEmailIds.Add(info.UID);

                    //解析从Pop3服务器发送过来的邮件信息
                    Mime m = Mime.Parse(bytes);
                    
                    string Attacht = "";
                    string content = "";
                    if (m != null)
                    {
                        string mailfrom = "";
                        string mailfromname = "";
                        if (m.MainEntity.From != null)
                        {
                            for (int i = 0; i < m.MainEntity.From.Mailboxes.Length; i++)
                            {
                                if (i == 0)
                                {
                                    mailfrom = (m.MainEntity.From).Mailboxes[i].EmailAddress;
                                }
                                else
                                {
                                    mailfrom += string.Format(",{0}", (m.MainEntity.From).Mailboxes[i].EmailAddress);
                                }
                                mailfromname = (m.MainEntity.From).Mailboxes[0].DisplayName != ""
                                                   ? (m.MainEntity.From).Mailboxes[0].DisplayName
                                                   : (m.MainEntity.From).Mailboxes[0].LocalPart;
                            }
                        }
                        string mailto = "";
                        string mailtotocollection = "";
                        if (m.MainEntity.To != null)
                        {
                            mailtotocollection = m.MainEntity.To.ToAddressListString();

                            for (int i = 0; i < m.MainEntity.To.Mailboxes.Length; i++)
                            {
                                if (i == 0)
                                {
                                    mailto = (m.MainEntity.To).Mailboxes[i].EmailAddress;
                                }
                                else
                                {
                                    mailto += string.Format(",{0}", (m.MainEntity.To).Mailboxes[i].EmailAddress);
                                }

                            }
                        }

                        mailTable.Rows.Add(new object[]
                                           {
                                               
                                               //(m.MainEntity.From).Mailboxes[0].DisplayName
                                               m.MainEntity.MessageID,info.UID, m.MainEntity.Subject, mailfrom, m.MainEntity.To, m.MainEntity.Date, m.MimeEntities.Length,m.BodyText ,
                                               m.BodyHtml
                                           });
                        
                    }
                    //获取附件
                    foreach (MimeEntity entry in m.Attachments)
                    {
                        string fileName = entry.ContentDisposition_FileName; //获取文件名称
                        string path = Server.MapPath("~\\Attch\\"+fileName);
                        if(File.Exists(path))
                        {
                            Random random=new Random();
                            int newfile = random.Next(1, 100000);
                            path = Server.MapPath("~\\Attch\\" + newfile.ToString());
                            Directory.CreateDirectory(path);
                            path +="\\"+ fileName;
                        }
                        byte[] data = entry.Data;
                        FileStream pFileStream = null;
                        pFileStream = new FileStream(path, FileMode.Create);
                        pFileStream.Write(data, 0, data.Length);
                        pFileStream.Close();
                    }
                }
                GridView1.DataSource = mailTable;
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                
                Response.Write(ex.Message);
            }
            
        }

    }

}

LumiSoftReceive.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LumiSoftReceive.aspx.cs" Inherits="LumiSoftReceive" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
     <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            CellPadding="4" ForeColor="#333333" GridLines="None" Width="1003px">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
            <asp:BoundField DataField="MessageID" HeaderText="MessageID" SortExpression="MessageID" ReadOnly="True" />
            <asp:BoundField DataField="Keywords" HeaderText="Keywords" SortExpression="Keywords" ReadOnly="True" />
            <asp:BoundField DataField="Title" HeaderText="主题" SortExpression="Title" ReadOnly="True" />
            <asp:BoundField DataField="frommail" HeaderText="发信人" SortExpression="frommail" ReadOnly="True" />
            <asp:BoundField DataField="tomail" HeaderText="收信人" SortExpression="tomail" ReadOnly="True" />
            <asp:BoundField DataField="senddate" HeaderText="时间" SortExpression="senddate" ReadOnly="True" />
            <asp:BoundField DataField="numbers" HeaderText="大小" SortExpression="numbers" ReadOnly="True" />
            <asp:BoundField DataField="content" HeaderText="内容" SortExpression="numbers" ReadOnly="True" />
             <asp:BoundField DataField="Attacht" HeaderText="附件" SortExpression="Attacht" ReadOnly="True" />
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>
晚上更新例子上来