3

I have one of the questions of the type that would usually make me say "Why would you want to do that" and assume it will be used for malicious purposes, but here goes...

How can I send email without user interaction, without implementing my own email sender?

Before any of you suggest it - I'm aware of Javamail and I've used the approach before so will fall back to that if I need to. I'm also aware of how to trigger a chooser and how to open a compose screen directly. What I want is none of those.

I have a feedback form in my app. 3 text fields and a button. When the user hits the button I send the data in the fields to myself, but to save increasing my app's size further I want to send the mail through whatever mail app is currently installed/default, all without further user interaction.

Is this possible?

Community
  • 1
  • 1
Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
  • I didn't think of the sent mails issue, good point. I'll look into the Google docs idea, I think it might be workable to call an API instead and then have that email as you've suggested. However as it's a fairly common problem I'm still interested in seeing if anyone knows how to do what I've actually asked – Nick Cardoso Feb 23 '14 at 00:26

6 Answers6

3

You can use the SMS functionality of your phone:

SmsManager sms = SmsManager.getDefault();
String myPhoneNumber = "800 333-1212";
String toEmailAddress = "foo@foo.com";
String myEmailBody = "Here is my email message";
sms.sendTextMessage( toEmailAddress,"1"+myPhoneNumber, myEmailBody, null, null);

Granted, your email won't look pretty, but... Also don't forget the permission SEND_SMS in your manifest. Obviously, this will not work on some tablets that only have wifi and no telephony.

Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
  • Im going to give this answer the bounty, just because its the most original solution I've seen (although not suitable for me) – Nick Cardoso Feb 29 '16 at 15:57
1

What you want to achieve is not possible with your conditions, however there is plenty of choice you have to achieve the same thing in a cleaner manner.

1.Use libraries and services like ACRA, as @Oliver has mentioned.

2.Implement a simple restful API and use it to send your data, you can use services like Google app engine to make this more convenient.

  1. Implement your own email sender which is not ideal at all.

Obviously your app need a backend.

M. Reza Nasirloo
  • 16,434
  • 2
  • 29
  • 41
  • Marking this as the correct answer for future visitors, although I gave the bounty to Kristy as that is the only answer which attempts to do this without interaction. (I just dont think it's the right solution for most peoples cases) – Nick Cardoso Feb 29 '16 at 16:09
1

You can't. There is no such thing as a default mail service on an Android phone. Gmail is commonly installed, but not all devices have a gmail account attached and not everyone uses it even if they do. If they use something like hotmail, yahoo, or a POP3/IMAP account there's absolutely no way to know or use it. The capability you want just isn't built into android.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
1

First, you can't do that from the Android phone.

If you really need to silently send an email from an Android phone, you can implement a web service that accepts input from your app and sends the mail from your server.

Option 2 is implement a web service that accepts the feedback without email.

DwB
  • 37,124
  • 11
  • 56
  • 82
0

There are several ways to send a mail without using mailing app:

1) Use webservice to send data to server and server sends the email to the specific user.

email data->server->mail to Specific user

2) Use java mail API for sending email. Sending Email in Android using JavaMail API without using the default/built-in app

Community
  • 1
  • 1
Rahil Ali
  • 957
  • 10
  • 25
-1

Android has concept of intents. You send Intent with data to the system and application that can handle that intent and chosen by system do what it can do with those data.

I believe Intens is the only reliable way to interact with default email client. You can't change behaviour of other apps, so you can't do that conceptually.

You must either implement email client in your app or just deal with behaviour of the default app.

  • An intent would merely open the email client and in many cases populate the content. The user would still have to then send the email themselves, and my email is exposed – Nick Cardoso Feb 29 '16 at 08:31
  • Yes, what I'm trying to say it isn't possible. You must build your own email client. Or, you may want to consider using REST client. It has 0 overhead but you must have your server, which is really easy with cloud solutions. It think that would satisfy all your needs. – Юрій Мазуревич Feb 29 '16 at 11:15