Reputation: 81
So sending an email is well documented on - https://developer.android.com/guide/components/intents-common.html#Email as follows:-
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
the above code i assume would open or ask you to open an email app(e.g. gmail) to send your email.
So i searched for another way to send a message without opening an app. and i found this :- http://www.edumobile.org/android/send-email-on-button-click-without-email-chooser/
The above link shows that you would have to basically build your own custom email app using gmail SMTP and JavaMail api
My question is, is there a way to send an email without
A. opening another application.
B. using external libraries like java mail etc?
Something like this :- https://i.sstatic.net/PUTNT.jpg
Upvotes: 2
Views: 607
Reputation: 29971
Of course you can send email without using external libraries or opening an app. There's no magic in JavaMail. It's all code you could write yourself. Start writing! It's just going to be a lot more effort than using JavaMail, but if that's what you want you can certainly do it.
Upvotes: 1
Reputation: 807
The answer is no, if you consider the following to be "external libraries":
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.security.AccessController;
import java.security.Provider;
If you do not consider those "external", I can give you code that works on Android 8.1 if you need. Tested with Gmail, Yahoo, and others.
Otherwise, AFAIK, there is no native Android API allowing one to send emails directly (i.e. not via an app).
Upvotes: 1