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

Exception triggered by MimeMessage addPart #153

Closed BL-Bl4ckBut7ch3r closed 6 months ago

BL-Bl4ckBut7ch3r commented 7 months ago

Hi there!

I managed to setup this client on Windows (irrevelant but, I use Win 11 pro) but as I send the e-mail out (which does arrive to the client) it crashes my program with no clear indication of what the SmtpClient screws up. Currently I'm using Qt Creator 5.0.2 with MinGW 64bit.

What I was able to track down so far are the following:

The line in my code that fails: message.addPart(&text);

Here is an example of what kind of data do I pass to the text variable: text.setText(ui->OutputLabel->toPlainText()); (OutputLabel is a QTextBrowser and from that straight the QString)

The QString looks like this all of the times: (example and also for consistency test I never changed the QString which I would send) hthIhtfadEc8stdEyvkKz9hsyxhIyvkKdEbtyoa5yvkKc8hIhthIhtfahthIyzbtdEbtyoa5yvkKc8hIyvkKz9hsc8hIc8ZryxdDraezhthIyzbtyxdDraezhthIyzbtJkhIa5gac8hIhxGcJkbtz9hsJkbtz9hsgac8gac89b9b==

And in debug mode I get this:

image

image

image

After this I tracked to the issue causer as much as I could (see after this phrase), but from here on I don't really know what should I do.

The function that kills it:

void MimeMessage::addPart(MimePart *part)
{
    if (typeid(*content) == typeid(MimeMultiPart)) {
        ((MimeMultiPart*) content)->addPart(part);
    };
}

Thank you for your help in advance!

attila-tokes commented 7 months ago

The MimeMultiPart.addPart(...) method takes ownership on the parts you pass as parameters. In the destructor the parts are also deleted, and I think you program may fail because of a double deletion of the MimeText object.

One thing you could try, is to create the MimeText object on the heap with new MimeText(...), instead of creating it on the stack.

BL-Bl4ckBut7ch3r commented 7 months ago

I will test it right away.

BL-Bl4ckBut7ch3r commented 7 months ago

That solves the issue. Thanks.

(Minor other thing is i get QObject::connect: No such signal QSslSocket::errorOccurred(QAbstractSocket::SocketError) I did modify the cpp to connect to error instead of errorOccurred but it didn't seemed to affect this one problem, although I will ignore it for now)

bluetiger9 commented 6 months ago

(Minor other thing is i get QObject::connect: No such signal QSslSocket::errorOccurred(QAbstractSocket::SocketError) I did modify the cpp to connect to error instead of errorOccurred but it didn't seemed to affect this one problem, although I will ignore it for now)

In recent versions of Qt 5/6 (>5.15) the QAbstractSocket::error signal was renamed to errorOccurred.