/
EmailMessage.cs
181 lines (160 loc) · 4.67 KB
/
EmailMessage.cs
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using Chilkat;
using System;
using System.Windows.Forms;
using MbcsUtils;
namespace MbcsListener
{
[Serializable()]
public class EmailMessage
{
protected string _UID;
protected string _toAddr;
protected string _fromAddr;
protected string _bcc;
protected string _subject;
protected DateTime _receiveDate;
protected string _filename;
protected string _message;
protected Chilkat.Email _emailMessage;
public EmailMessage()
{
}
public EmailMessage(string toAddr, string fromAddr, string bcc, string subject, DateTime receiveDate, string filename, string uid = "")
{
_toAddr = toAddr;
_fromAddr = fromAddr;
_bcc = bcc;
_subject = subject;
_receiveDate = receiveDate;
_filename = filename;
_UID = uid;
}
public EmailMessage(string uid, Chilkat.Email msg)
{
_toAddr = msg.GetTo(0);
_fromAddr = msg.From.ToString();
_bcc = "";
for (int i = 0; i <= msg.NumCC - 1; i++)
{
_bcc += msg.GetCC(i) + " ";
}
_subject = msg.Subject;
_receiveDate = msg.EmailDate;
_filename = null;
_message = msg.GetPlainTextBody();
_UID = msg.Uidl;
_emailMessage = msg;
}
public void fetchMessage(SmtpConfig smtpAcct)
{
string Username;
string Password;
string Host;
int Port;
string Email;
bool SSL;
bool TSL;
long authenticationType;
Chilkat.MailMan mailman = new Chilkat.MailMan();
bool success = mailman.UnlockComponent("BARTMNMAILQ_3K24X6hk7C2J");
if (!success)
{
MessageBox.Show("Could not initialize email component");
return;
}
if (smtpAcct != null)
{
Username = smtpAcct.in_userName;
Password = smtpAcct.in_password;
Host = smtpAcct.in_server;
Port = smtpAcct.in_port;
Email = smtpAcct.emailAddress;
SSL = smtpAcct.in_SSL;
TSL = smtpAcct.in_TSL;
authenticationType = smtpAcct.in_authentication;
}
else
{
GlobalShared.Log.Log((int)LogClass.logType.Warning, "No POP configuration found", false);
return;
}
mailman.MailHost = Host;
//TCP port for connection
mailman.MailPort = (ushort)Port;
//Username to login to the POP3 server
mailman.PopUsername = Username;
//Password to login to the POP3 server
mailman.PopPassword = Password;
// SSL Interaction type
if (TSL)
{
mailman.StartTLS = true;
}
else if (SSL)
{
mailman.PopSsl = true;
}
try
{
_emailMessage = mailman.FetchEmail(_UID);
_message = _emailMessage.GetPlainTextBody();
}
catch (System.Exception ex)
{
}
finally
{
mailman = null;
}
}
public static int sort(EmailMessage x, EmailMessage y)
{
return y.receiveDate.CompareTo(x.receiveDate);
}
public string toAddr
{
get { return _toAddr; }
set { _toAddr = value; }
}
public string fromAddr
{
get { return _fromAddr; }
set { _fromAddr = value; }
}
public string bcc
{
get { return _bcc; }
set { _bcc = value; }
}
public string subject
{
get { return _subject; }
set { _subject = value; }
}
public DateTime receiveDate
{
get { return _receiveDate; }
set { _receiveDate = value; }
}
public string message
{
get { return _message; }
set { _message = value; }
}
public string filename
{
get { return _filename; }
set { _filename = value; }
}
public string UID
{
get { return _UID; }
set { _UID = value; }
}
public Chilkat.Email emailMessage
{
get { return _emailMessage; }
set { _emailMessage = value; }
}
}
}