狠狠色丁香婷婷综合尤物/久久精品综合一区二区三区/中国有色金属学报/国产日韩欧美在线观看 - 国产一区二区三区四区五区tv

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

C# 讀取eml文件 例子(解析eml文件)

admin
2017年10月21日 18:25 本文熱度 7048
【實例簡介】標題/郵箱/信件內容等

【實例截圖】


【核心代碼】


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ADODB;
using CDO;
using System.Diagnostics;
using Stream = ADODB.Stream;
using System;
 
namespace EmlReader.WinForm
{
    public partial class EmlViewer : Form
    {
        public EmlViewer()
        {
            InitializeComponent();
        }
 
        public void OpenEml(string filepath)
        {
            try
            {
                var stream = new StreamClass();
                stream.Open();
                stream.LoadFromFile(filepath);
                stream.Flush();
 
                var mail = new MessageClass();
                mail.DataSource.OpenObject(stream, "_Stream");
                mail.DataSource.Save();
 
                fromBox.Text = mail.From;
                toBox.Text = mail.To;
                ccBox.Text = mail.CC;
                bccBox.Text = mail.BCC;
                subjectBox.Text = mail.Subject;
                bodyBox.Text = mail.TextBody;
 
                attachmentsPanel.Controls.Clear();
                foreach (IBodyPart attachment in mail.Attachments)
                {
                    var linkLabel = new LinkLabel
                                        {
                                            Text = attachment.FileName,
                                            AutoSize = true,
                                        };
                    linkLabel.Links.Add(0, linkLabel.Text.Length, attachment.GetDecodedContentStream());
                    linkLabel.LinkClicked  = LinkLabelLinkClicked;
                    linkLabel.Disposed  = LinkLabelDisposed;
                    attachmentsPanel.Controls.Add(linkLabel);
                }
                stream.Close();
            }
            catch (Exception)
            {
                MessageBox.Show(this, "An error occured while opening the file", "Email could not be opened",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 
        static void LinkLabelDisposed(object sender, EventArgs e)
        {
            var linkLabel = sender as LinkLabel;
            if (linkLabel == null) return;
            foreach (LinkLabel.Link link in linkLabel.Links)
                ((Stream)link.LinkData).Close();
        }
 
        static void LinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var linkLabel = sender as LinkLabel;
            if (linkLabel == null) return;
 
            var fileName = linkLabel.Text;
            linkLabel.LinkVisited = true;
 
            var stream = e.Link.LinkData as Stream;
            if (stream == null) return;
 
            var tempFile = Path.Combine(Path.GetTempPath(), fileName);
            stream.SaveToFile(tempFile, SaveOptionsEnum.adSaveCreateOverWrite);
            Process.Start(tempFile);
        }
 
        private void EmlViewerDragDrop(object sender, DragEventArgs e)
        {
            var files = (string[])e.Data.GetData(DataFormats.FileDrop);
            OpenEml(files.First());
        }
 
        private void EmlViewerDragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
        }
 
        private void OpenButtonClick(object sender, EventArgs e)
        {
            openFileDialog.ShowDialog(this);
        }
 
        private void OpenFileDialogFileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {
            var dialog = sender as FileDialog;
            if (dialog == null) return;
            OpenEml(dialog.FileName);
        }
    }
}

該文章在 2017/10/21 18:25:30 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved