1

How can I open the default compose mail window from the user's mail app from within a Qt app?

I found there is some class for mobile with Qtmobility, but I don't have access to this class as I'm working on a desktop app.

I also found people to use a URL sheme with a mailto in it. This isn't working for me because the html is stripped at some point, probably because of the url being too long and the html is not rendered in html but in plain text.

How can I precompose a mail in Qt and open the default mail app?

Vincent Duprez
  • 3,772
  • 8
  • 36
  • 76

2 Answers2

5

There is no built in way in Qt to send email with HTML formatting. The Mailto method will work for unformatted text, e.g.

QDesktopServices::openUrl(QUrl("mailto:?to=recipient@example.com&subject=The subject of an email&body=Here is some email body text", QUrl::TolerantMode));

But this cannot be used for html formatted text.

If you absolutely need HTML you will need to look at the options for your platform(s):

Community
  • 1
  • 1
docsteer
  • 2,506
  • 16
  • 16
0

Old topic but :

You could also try another way, as I did, using a web service. I have a php web service that send email to a specific mail address, so I just send the message data to this web service, that will handle the rest for me.

This is to abstract yourself of using a desktop software that most of the time users don't have ( we all use gmail anyway, so you know ... ). In php :

// sending mail to  my@address.com  
    $headers ='From: sender@address.com'."\n";
    $headers .="Reply-To: replyto@address.com"."\n";
    $headers .='Content-Type: text/plain; charset="iso-8859-1"'."\n";
    $headers .='Content-Transfer-Encoding: 8bit';
    mail('my@address.com', '[TAG] mail subject', "some body text.", $headers); 

Careful of security though !

sebius
  • 102
  • 2
  • 14
  • Hi Sebius, Thanks for answering but this is actually wrong to this Question. I'm not asking how to send mail but how to prepare a mail to be sent, not actually sending it. Furthermore, the way you present it does not archives the sent mail in the users sent folder (we don't have access to the users mailbox) – Vincent Duprez Mar 24 '18 at 13:28