Sending email attachment via default email client



  • Hi,
    Using QDesktopServices we could send email via windows default email client
    such as Thunderbird.

    QDesktopServices::openUrl(QUrl("mailto:?subject=test&body=test&attach=C:/myfolder/file.pdf") );
    

    But thunderbird ignores file attachment. Is there any platform independent
    method to send attach file via default email client? or at least working
    method for windows? Some suggestion from web is to use mapi.h. but it seems
    not working well with mingw compiler.



  • @samdol
    Not sure exactly what you want by "default email client". Probably no gurarantee that any such will accept attachments.

    If you go down the route of external library, unless you need facilities of MAPI I would recommend using SMTP (SMTP does do attachments).

    I believe I also saw the other day that someone has implemented a command-line SMTP client to do mailing, if that does attachments it could be a simple way avoiding coding --- but then your target machines would need it/you'd have to supply with your app.



  • @samdol said in Sending email attachment via default email client:

    Is there any platform independent method to send attach file via default email client?

    Short answer: no, because it would represent a security vulnerability so most modern clients explicitly prevent that to be possible



  • @samdol said in Sending email attachment via default email client:

    Hi,
    Using QDesktopServices we could send email via windows default email client
    such as Thunderbird.

    QDesktopServices::openUrl(QUrl("mailto:?subject=test&body=test&attach=C:/myfolder/file.pdf") );
    

    But thunderbird ignores file attachment.

    Oh, hang on, it may just be the way you're specifying your attachment command-line. See https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options:

    attachment='file:///c:/test.txt'

    Try that (assuming "command-line options" applies when Url, I don't know, worth a try)?



  • @JNBarchan
    I saw some windows app launches thunderbird with file attachment. So it is possible to do in windows. They may uses MAPI. As you suggested I may implement SMTP client on my program, but I don't want to encourage people enter their password in my program. Besides, people have to enter their password every time they use the program.

    attachment='file:///c:/test.txt'
    Unfortunately, this did not make change. It launches my default email client, thunderbird, and it passes subject and body, but thunderbird ignores attachment.



  • This post is deleted!


  • Is there any platform independent method to send attach file via default email client?

    I saw some windows app launches thunderbird with file attachment.

    Again, some clients support the attach= syntax but you can't guarantee it works on every platform and email client as it's not part of the standard.
    MS Outlook 2007 or newer, for example, explicitly prevents it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.