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

Hooking into waitForMailSent #142

Closed ChriswZeroOne closed 1 year ago

ChriswZeroOne commented 1 year ago

Hello,

Quick response on my other issue, your suggestion worked perfectly; Thank you. However is it possible to hook into waitForMailSent to add a progress bar. I see it takes a timeout variable of 30000 default; If I was to supply my own timeout to it and loop until it returns true (of course checking for errors) would this work? or is email processing stopped on timeout? Or is there a better way to do this?

bluetiger9 commented 1 year ago

Hi @ChriswZeroOne!.

The library does not have a feature to give you a progress on the mail sending action...

The .waitForMailSent() method gives you immediate feedback when the mail sending either success or fails with an error. But, there is no intermediate process information, as we are just sending data to the server.

If you're sending emails with large attachments, you could try to add a progress hook in MimeFile::writeContent / MimePart::writeContent.

Right now MimePart::writeContent dumps the entire content at once on the QIODevice. What you could do is to split up content into multiple chunks (ex. ~64 kB), and write these chunks in a blocking fashion to QIODevice by calling .write() first then .waitForBytesWritten(). After each successfully written chunks you could upgrade a progress percentage.

Thanks!