Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Send email using default mail client /gmail in Android
QtWS25 Last Chance

Send email using default mail client /gmail in Android

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 3 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GoodMorninSunshine
    wrote on last edited by
    #1

    Hi All,

    In my android app, I want to email some data using the defualt email client (most often gmail). I found that I can use "mailto:" approach if Im not attaching anything. QDesktopServices::openURL(QURL("mailto:?subject=Test&body= "test"))

    But I need to attach a file, and I found that its possible to do this using QMessage and QMessageServices classes in Qt Mobility. Im working on Qt 5.3 and it seems like some modules in Qt Mobility are integrated into the Qt Core itself.

    My Questions are :

    • Has QMessage and QMessageSErvices Modules being integrated in the Qt Core? If so, under what name?
    • Can I manually install Qt Mobility with Qt 5.3?
    • Any other approach that I can use for my task?

    Thank you very much for your support... I seem to be going round and round in circles...

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Khachatur
      wrote on last edited by
      #2

      Hi.

      You can write the method for sending email in your Java class and call it from C++ code.

      For example:

      @
      public void SendEmail(String attachment)
      {
      File file = new File(attachment);
      if(file.exists())
      {
      Intent intent = new Intent(Intent.ACTION_SEND);
      intent.setType("message/rfc822");
      intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"someemail@gmail.com"});
      intent.putExtra(Intent.EXTRA_SUBJECT, "Some subject");
      intent.putExtra(Intent.EXTRA_TEXT, "Hello, World!");
      intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
      try
      {
      startActivity(Intent.createChooser(intent, "Send mail..."));
      } catch (android.content.ActivityNotFoundException ex) {
      android.widget.Toast.makeText(m_instance, "There are no email clients installed.", android.widget.Toast.LENGTH_SHORT).show();
      }
      }
      }
      @

      Calling SendEmail function from C++ code:
      @
      // Get activity
      QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
      if(activity.isValid())
      {
      // Path to attachment
      QAndroidJniObject jpath = QAndroidJniObject::fromString(QString(path));
      // Calling method SendEmail
      activity.callMethod<void>("SendEmail", "(Ljava/lang/String;)V", jpath.object<jstring>());
      }
      @

      1 Reply Last reply
      1
      • N Offline
        N Offline
        nando76
        wrote on last edited by
        #3

        Please take a look also at this thread:

        "Send Mail on Android":http://qt-project.org/forums/viewthread/49056/

        Greetings
        Nando

        1 Reply Last reply
        1
        • G Offline
          G Offline
          GoodMorninSunshine
          wrote on last edited by
          #4

          Thank you very much Khachatur and nando76. This solved my problem!

          Thanks!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved