washington
washington

Reputation: 88

QT email client using IMAP4

I am developing a QT program that will check for new mails from gmail and download them using IMAP4 protocol. I am unable to write a command to display the messages in my inbox. please help me. Here is a sample of my code.

    socket->connectToHostEncrypted("imap.gmail.com", 993);

    if(!socket->waitForConnected(50000)){
        qDebug()<<"Error:"<<socket->errorString();
    }
}

void MySocket::connected(){
    qDebug()<<"**********\nconnected....\n*********";

    QByteArray byteArray("a001 LOGIN username password");
    socket->write(byteArray);
    socket->write("\r\n");

    socket->waitForReadyRead();

    byteArray.clear();
    byteArray.append("A002 LIST inbox");
    socket->write(byteArray);
    socket->write("\r\n");

}

Upvotes: 0

Views: 3983

Answers (2)

Jan Kundr&#225;t
Jan Kundr&#225;t

Reputation: 3816

Writing an IMAP client is far from trivial. Have you considered using some existing IMAP library that is written with Qt? I can of course recommend the code from Trojitá, or the KDE's IMAP code.

Upvotes: 1

Gigi
Gigi

Reputation: 29461

You are obviously not familiar with the IMAP protocol, so you will need to read RFC3501 if you want to be able to work with the protocol effectively.

I also suggest you check out my blog post IMAP: Downloading emails to get up and running quickly.

The LIST command will list the folders in your account. What you need to download emails in a folder or view their metadata is the FETCH Command. Again, read the RFC to learn what it offers. It is normally expected that you've done your research before asking on Stack Overflow.

Upvotes: 1

Related Questions