bluetiger9 / SmtpClient-for-Qt

An SMTP Client writen in C++ for Qt. Allows applications to send emails (MIME with text, html, attachments, inline files, etc.) via SMTP. Supports SSL and SMTP authentication.
https://github.com/bluetiger9/SmtpClient-for-Qt/wiki
GNU Lesser General Public License v2.1
449 stars 226 forks source link

CRITICAL: Timeout is not working #125

Closed ghorwin closed 1 year ago

ghorwin commented 1 year ago

The function

void SmtpClient::waitForEvent(int msec, const char *successSignal)
{
    QEventLoop loop;
    QObject::connect(this, successSignal, &loop, SLOT(quit()));
    QObject::connect(this, SIGNAL(error(SmtpClient::SmtpError)), &loop, SLOT(quit()));

    if(msec > 0)
    {
        QTimer timer;
        timer.setSingleShot(true);
        connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
        timer.start(msec);
    }

    loop.exec();
}

takes a timeout argument. It is expected, that the QTimer triggers QEventLoop::quit() after said timeout, yet this never happens. As a consequence, the loop 'hangs' until the socket sends a NetworkError (via signal error()) and by this triggers the quit() slot (on my machine after roughly 50 seconds).

I am not sure why this is, but the problem can be readily reproduced - at least on Windows 10.

Unless this bug is fixed, using the synchronous API is not realiably usable in a situation where the connection to mail server is unstable.

ChaseyLain commented 1 year ago

Hello! The issue is that the QTimer is declared inside of the if() statement. This causes the QTimer object to be destroyed before loop.exec() is called.

Simply the line "QTimer timer" needs to be moved before "if(msec > 0)". That is all.

I'm not familiar with how making changes here works on github so I cannot change it myself, but that will fix it for you.

Greetings!

ghorwin commented 1 year ago

Thanks, works!

cheicktra2 commented 1 year ago

Hello, thank you for your message. I need your service if possible have good smtp to launch messages accompanied by files thank you I also have

Le lun. 28 nov. 2022 à 14:04, Andreas Nicolai @.***> a écrit :

Thanks, works!

— Reply to this email directly, view it on GitHub https://github.com/bluetiger9/SmtpClient-for-Qt/issues/125#issuecomment-1329163969, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4N6FZSNROVZYSJOPS6H3B3WKS3YLANCNFSM6AAAAAARXMKLPU . You are receiving this because you are subscribed to this thread.Message ID: @.***>