Answer the question
In order to leave comments, you need to log in
C++/CLI Working IMAP using chikkat library?
Good afternoon, we were given the task to make a mail client in C++/CLI. I chose the chilkat library as a solution, as it is very flexible and multifunctional. Implemented the SMTP protocol, but IMAP could not be fully implemented.
I was able to log in to the server and got access to folders with messages, but when I try to display a message or view the list, I always get "true" instead of the sender or in general instead of the message itself. Whatever I tried, I searched through the documentation, but still did not find how to turn "true" into text.
Here is a link to the library documentation:
Here is the code from my project:
textBox4->Clear();
const char* imapC;
if (comboBox1->SelectedIndex == 1)
{
imapC = "imap.mail.ru";
}
if (comboBox1->SelectedIndex == 2)
{
imapC = "imap.gmail.com";
}
if (comboBox1->SelectedIndex == 3)
{
imapC = "imap.yandex.ru";
}
CkMime mime;
/*IntPtr loginS = Marshal::StringToHGlobalAnsi(textBox2->Text + "\r\n");
const char* loginC = (char*)loginS.ToPointer();
IntPtr passwS = Marshal::StringToHGlobalAnsi(textBox3->Text + "\r\n");
const char* passwC = (char*)passwS.ToPointer();*/
if (comboBox1->SelectedIndex != 0)
{
CkGlobal glob;
bool success = glob.UnlockBundle("Anything for 30-day trial");
if (success == true) {
textBox4->Text += "Статус: Дамп библиотеки загружен" + "\r\n";
}
CkImap imap;
imap.put_Ssl(true);
imap.put_Port(993);
success = imap.Connect(imapC);
if (success != true) {
textBox4->Text += "Статус: Не подключился" + "\r\n";
}
else {
textBox4->Text = "Статус: Подключено" + "\r\n";
}
success = imap.Login("[email protected]", "password");
if (success != true) {
textBox4->Text += "Статус: Неверные данные" + "\r\n";
}
else {
textBox4->Text += "Статус: Вы авторизовались" + "\r\n";
}
success = imap.SelectMailbox("Inbox");
if (success != true) {
textBox4->Text += "Статус: Такой папки нет" + "\r\n";
}
else {
textBox4->Text += "Статус: Выбрана папка - " + "Входящие\r\n\r\n";
}
CkMessageSet* messageSet = 0;
// We can choose to fetch UIDs or sequence numbers.
bool fetchUids = true;
// Get the message IDs of all the emails in the mailbox
messageSet = imap.Search("ALL", fetchUids);
if (imap.get_LastMethodSuccess() == false) {
textBox4->Text += "Статус: Ошибка папки" + "\r\n";
}
CkEmailBundle* bundle = 0;
bundle = imap.FetchHeaders(*messageSet);
if (imap.get_LastMethodSuccess() == false) {
delete messageSet;
textBox4->Text += "Статус: Ошибка папки" + "\r\n";
}
bundle = imap.FetchSequenceHeaders(1, imap.get_NumMessages());
if (imap.get_LastMethodSuccess() != true) {
textBox4->Text += "Статус: Ошибка папки c письмами" + "\r\n";
}
if (bundle->get_MessageCount() == 0) {
textBox4->Text += "Статус: Нет сообщений в папке" + "\r\n";
delete bundle;
}
const char *fetchAttachmentString(CkEmail &emailObject, int attachmentIndex, const char *charset);
textBox4->Text += "Всего писем - " + Convert::ToString(bundle->get_MessageCount()) + "\r\n\r\n";
int j = 0;
int numEmails = bundle->get_MessageCount();
while (j < numEmails) {
CkEmail* email = bundle->GetEmail(j);
textBox4->Text += "#" + (j + 1) + "\r\n";
textBox4->Text += "От кого: ";
textBox4->Text += Convert::ToString(email->ck_from()) + ". ";
textBox4->Text += "Тема: ";
textBox4->Text += Convert::ToString(email->subject()) + "\r\n";
delete email;
j = j + 1;
}
delete bundle;
// Disconnect from the IMAP server.
success = imap.Disconnect();
}
else {
MessageBox::Show("Укажите узел IMAP", "Ошибка");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question