3

I use Qt's openUrl() with a 'mailto' link to open the user's email client, as the top answer here demonstrates. This works fine for Outlook, but if the user's email client is Chrome configured to open gmail when it receives a mailto: link, the entire to, subject, and body all end up in the 'to' field of the email.

QDesktopServices::openUrl(QUrl("mailto:" + to + "&subject=" + subject + "&body=" + body, QUrl::TolerantMode));

I have tried first encoding the subject and body, but this has not helped. Any ideas how to either fix this, or for an alternate method? (Using Qt 5.9.5, but this affected former versions such as 5.7.1 as well.)

scopchanov
  • 7,966
  • 10
  • 40
  • 68
Vern Jensen
  • 3,449
  • 6
  • 42
  • 59

1 Answers1

4

This is actually not a Qt related issue. The problem is in the HTML code.

According to this answer, you should change &subject to ?subject in order to make it work.

So your code should be:

QDesktopServices::openUrl(QUrl("mailto:" + to + "?subject=" + subject + "&body=" + body, QUrl::TolerantMode));

I've just tested it with Qt 5.10.0 and Chrome 68.0.3440.106 and it works.

scopchanov
  • 7,966
  • 10
  • 40
  • 68