August 9, 2012

QtTuomi QtTuomi
Lab Rat
4 posts

Qml: sending email with Qt.openUrlExternally

 

Hello everybody,

I’m new to Qml and I’m trying to write an app, which should send an email when clicking a mouse area. This is, what I have already written:

  1. // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
  2. import QtQuick 1.1
  3.  
  4. Rectangle {
  5.     id: rectangle1
  6.     width: 360
  7.     height: 360
  8.     MouseArea {
  9.         id: sendButton
  10.         width: parent.width/2
  11.         height: parent.height/2
  12.         anchors.horizontalCenter: parent.horizontalCenter
  13.         anchors.verticalCenter: parent.verticalCenter
  14.         onClicked: {
  15.                         Qt.openUrlExternally("mailto: to@adress.com" +
  16.                                  "?subject=This is a subject" +
  17.                                  "&body=This is the message")
  18.         }
  19.  
  20.         Text {
  21.             id: textSendeMail
  22.             text: qsTr("Sende Mail")
  23.             font.family: "MS Shell Dlg 2"
  24.             anchors.fill: parent
  25.             verticalAlignment: Text.AlignVCenter
  26.             horizontalAlignment: Text.AlignHCenter
  27.             font.pixelSize: 16
  28.         }
  29.     }
  30. }

Now, when clicking this area, Outlook starts. I mean, this is clear, as the name says to open the url externally. But is there a way to send an email directly, without opening Outlook.

I wrote such a function in C# already, maybe it would be easier to understand, what I mean, when I just show you the C#-Code:

  1.                 MailMessage message = new MailMessage();
  2.                 message.Subject = "This is the subject";
  3.                 message.Body = "Here is the message";
  4.                 message.From = new MailAddress("noreply@myaddress.com");
  5.                 message.To = new MailAddress("destination@address.com");
  6.                 SmtpClient smtp = new SmtpClient(ip);
  7.                 smtp.Send(message);

1 reply

August 10, 2012

mbrasser mbrasser
Ant Farmer
452 posts

The QtQuick module itself doesn’t provide any support for this. There are a number of plugins available, including a Messaging plugin (see http://doc.qt.nokia.com/qtmobility/qml-plugins.html for the list of plugins), though from a quick look it appears it only supports reading messages. If that is the case, you might need to write your own C++ plugin to handle this functionality.

Regards,
Michael

 
  ‹‹ Get list of future dates?      Bug? Appending two items to a QML ListModel, then model.move(1,0,1); causes crash. ››

You must log in to post a reply. Not a member yet? Register here!