9 / 9 / 5
Регистрация: 05.02.2012
Сообщений: 147
|
|
1
|
Не могу загрузить письма с ящика
20.09.2013, 20:18. Показов 1309. Ответов 0
Здравствуйте! Пишу программу для работы с электронной почтой.Проблема такова: один раз прога отработала на ура и загрузила в dataGrid названием писем и адрес отправителя. После отказывается грузить письма на отрез. Переменная uids, которая хранит количество писем равна нулю. Коннект к самому imap серверу вроде как проходит. Использую библиотеку mail.dll. В чем я туплю, скажите пожалуйста? Заранее спасибо!
метод загрузки почты
C# | 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
| private void loadFromMailboxToolStripMenuItem_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
Load_mail l_m = new Load_mail();
string subject;
string mail_address;
string login = t_i.take_login("MailRUAccount.cad"); /* считывает в переменную login строку из файла, которая является логином*/
string password= t_i.take_password("MailRUAccountPass.cad"); /* считывает пароль*/
using (Imap imap = new Imap())
{
imap.Connect(Account.imap_hostMailRU); /*imap.mail.ru*/
imap.Login(login, password);
imap.SelectInbox();
List<long> uids = imap.Search(Flag.Unseen); //количиство писем
int mess_count=0;
mess_count = Convert.ToInt32(uids.Count());
if (mess_count == 0)
{
MessageBox.Show("No mail", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
dataGridView1.RowCount = mess_count; //кол-во строк
}
int i = 0;
foreach (long uid in uids)
{
IMail email = new MailBuilder().CreateFromEml(imap.GetMessageByUID(uid));
subject = l_m.ret_subject(email);
mail_address = l_m.return_mail_address(email);
Console.WriteLine(mail_address);
dataGridView1.Rows[i].Cells[0].Value = mail_address;
dataGridView1.Rows[i].Cells[1].Value = subject;
i++;
}
imap.Close();
}
MessageBox.Show("Mail loaded!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
} |
|
вот пример, который давался с библиотекой
C# | 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
| using System;
using System.Collections.Generic;
using System.Text;
using Limilabs.Client.IMAP;
using Limilabs.Mail;
using Limilabs.Mail.Headers;
using Limilabs.Mail.MIME;
namespace ImapDownload
{
class Program
{
private const string _server = "imap.server.com";
private const string _user = "user";
private const string _password = "password";
static void Main()
{
using (Imap imap = new Imap())
{
imap.Connect(_server); // Use overloads or ConnectSSL if you need to specify different port or SSL.
imap.Login(_user, _password); // You can also use: LoginPLAIN, LoginCRAM, LoginDIGEST, LoginOAUTH methods,
// or use UseBestLogin method if you want Mail.dll to choose for you.
imap.SelectInbox(); // You can select other folders, e.g. Sent folder: imap.Select("Sent");
List<long> uids = imap.Search(Flag.Unseen); // Find all unseen messages.
Console.WriteLine("Number of unseen messages is: " + uids.Count);
foreach (long uid in uids)
{
IMail email = new MailBuilder().CreateFromEml( // Download and parse each message.
imap.GetMessageByUID(uid));
ProcessMessage(email); // Display email data, save attachments.
}
imap.Close();
}
}
private static void ProcessMessage(IMail email)
{
Console.WriteLine("Subject: " + email.Subject);
Console.WriteLine("From: " + JoinAddresses(email.From));
Console.WriteLine("To: " + JoinAddresses(email.To));
Console.WriteLine("Cc: " + JoinAddresses(email.Cc));
Console.WriteLine("Bcc: " + JoinAddresses(email.Bcc));
Console.WriteLine("Text: " + email.Text);
Console.WriteLine("HTML: " + email.Html);
Console.WriteLine("Attachments: ");
foreach (MimeData attachment in email.Attachments)
{
Console.WriteLine(attachment.FileName);
attachment.Save(@"c:\" + attachment.SafeFileName);
}
}
private static string JoinAddresses(IList<MailBox> mailboxes)
{
return string.Join(",",
new List<MailBox>(mailboxes).ConvertAll(m => string.Format("{0} <{1}>", m.Name, m.Address))
.ToArray());
}
private static string JoinAddresses(IList<MailAddress> addresses)
{
StringBuilder builder = new StringBuilder();
foreach (MailAddress address in addresses)
{
if (address is MailGroup)
{
MailGroup group = (MailGroup) address;
builder.AppendFormat("{0}: {1};, ", group.Name, JoinAddresses(group.Addresses));
}
if (address is MailBox)
{
MailBox mailbox = (MailBox) address;
builder.AppendFormat("{0} <{1}>, ", mailbox.Name, mailbox.Address);
}
}
return builder.ToString();
}
};
} |
|
Ниже сама либа.
0
|