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

Client Crashes on text.setText #123

Closed joshorenberg closed 1 year ago

joshorenberg commented 2 years ago

Hi the client is crashing for me on the step text.setText(string); Application output says: Critical error detected c0000374

Here is a backtrace: backtrace bt

Here is the code as borrowed from the example:

        MimeMessage message;
        EmailAddress sender("sample@sample.com", "sample program");
        message.setSender(sender);

        EmailAddress to(iterator.key(), "");
        message.addRecipient(to);

        message.setSubject("Subject");

        MimeText text;
        text.setText("Hi,\nThis is a simple email message.\n");
        message.addPart(&text);

I am running Qt Creator based on Qt 5.15.2. Thanks!

ghorwin commented 1 year ago

Note, addPart() transfers ownership (should be documented!). You mustn't do this with stack variables. Use:

MimeText * text = new MimeText;
...
message.addPart(text);
bluetiger9 commented 1 year ago

@ghorwin, addPart() does not actually takes ownership of part you're adding. It just expects a MimePart * pointer, and the object must remain valid unit you call the sendMail() method. This works with stack variables too, as long you're calling the sendMail() within the same method. Thanks!