- How to open an installed app from an email URL in Android? [duplicate]
- 3 Answers 3
- How to send emails from my Android application?
- 24 Answers 24
- How to start an application using Android ADB tools
- 14 Answers 14
- Sending Email in Android using JavaMail API without using the default/built-in app
- 25 Answers 25
- Steps to create a sample Project:
- Mail Application
- Android Email App Using Javamail API in Android Studio
- Android Email App – Video
- Download Javamail API for Android
- Creating Android Email App in Android Studio
- Get source code of Android Email App
- Checkout these tutorials as well:
- 123 thoughts on “Android Email App Using Javamail API in Android Studio”
How to open an installed app from an email URL in Android? [duplicate]
I want to open my app from an email URL, basically like the example shown below for Twitter.com.
Email with link:
Selection to open app or browser:
After you click on the app choice, the Twitter app opens:
I tried the following code, but it is not working:
If anyone has a proper answer, please write some examples here.
3 Answers 3
The following code worked for me:
With the email link set as http://www.my.app.com/launch .
Ex: Your url will be something like https://roadies.com and you have the intent filter in manifest as below
For me, none of the answers posted here worked. I tried tens of different syntaxes without any success. I was getting a parsing error while building the app via Cordova.
I finally encountered this answered which led me on the right track.
So I created a hook in the PROJECT_ROOT/hooks/after_prepare/ folder called 010_add_intent_filters.sh . Here is the content of this hook :
This finally worked. No modification to config.xml is required if you take the hook path. I hope this helps someone in need.
PS: I am convinced Cordova is a great technology, but I have rarely seen such a badly documented library. How painful it is to work with it is just unbelievable.
Источник
How to send emails from my Android application?
I am developing an application in Android. I don’t know how to send an email from the application?
24 Answers 24
The best (and easiest) way is to use an Intent :
Otherwise you’ll have to write your own client.
Use .setType(«message/rfc822») or the chooser will show you all of the (many) applications that support the send intent.
I’ve been using this since long time ago and it seems good, no non-email apps showing up. Just another way to send a send email intent:
I was using something along the lines of the currently accepted answer in order to send emails with an attached binary error log file. GMail and K-9 send it just fine and it also arrives fine on my mail server. The only problem was my mail client of choice Thunderbird which had troubles with opening / saving the attached log file. In fact it simply didn’t save the file at all without complaining.
I took a look at one of these mail’s source codes and noticed that the log file attachment had (understandably) the mime type message/rfc822 . Of course that attachment is not an attached email. But Thunderbird cannot cope with that tiny error gracefully. So that was kind of a bummer.
After a bit of research and experimenting I came up with the following solution:
It can be used as follows:
As you can see, the createEmailOnlyChooserIntent method can be easily fed with the correct intent and the correct mime type.
It then goes through the list of available activities that respond to an ACTION_SENDTO mailto protocol intent (which are email apps only) and constructs a chooser based on that list of activities and the original ACTION_SEND intent with the correct mime type.
Another advantage is that Skype is not listed anymore (which happens to respond to the rfc822 mime type).
Источник
How to start an application using Android ADB tools
How do I send an intent using Android’s ADB tools?
14 Answers 14
Or you can use this directly:
You can also specify actions to be filter by your intent-filters:
/.bash_profile to be much faster function androidrun() < ant clean debug adb shell am start -n $1/$1.MainActivity >and its usage androidrun com.example.test
It’s possible to run an application specifying the package name only using the monkey tool by follow this pattern:
The command is used to run the app using the monkey tool which generates random input for the application. The last part of the command is an integer which specifies the number of generated random input for the app. In this case the number is 1, which in fact is used to launch the app (icon click).
Or, you could use this:
/android-sdk-linux/build-tools/20.0.0/aapt dump badging yourapp.apk , which will list the following entry: launchable-activity: name=’com.company.android.package.YourLaunchableActivity’
Linux and Mac users can also create a script to run an APK file with something like the following:
Create a file named «adb-run.sh» with these three lines:
Then «chmod +x adb-run.sh» to make it executable.
Now you can simply:
The benefit here is that you don’t need to know the package name or launchable activity name. Similarly, you can create «adb-uninstall.sh myapp.apk»
Note: This requires that you have Android Asset Packaging Tool ( aapt ) in your path. You can find it under the new build tools folder in the SDK.
Step 1: First get all the package names of the apps installed in your device, by using:
Step 2: You will get all the package names. Copy the one you want to start using ADB.
Step 3: Add your desired package name in the below command.
to start the Es explorer.
Also, I want to mention one more thing.
When you start an application from adb shell am , it automatically adds FLAG_ACTIVITY_NEW_TASK flag which makes behavior change. See the code.
For example, if you launch a Play Store activity from adb shell am , pressing the ‘Back‘ button (hardware back button) wouldn’t take you your app. Instead, it would take you previous Play Store activity if there was some (if there was not a Play store task, then it would take you to your app). FLAG_ACTIVITY_NEW_TASK documentation says:
if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in
This caused me to spend a few hours to find out what went wrong.
So, keep in mind that adb shell am add FLAG_ACTIVITY_NEW_TASK flag.
Источник
Sending Email in Android using JavaMail API without using the default/built-in app
I am trying to create a mail sending application in Android.
This will launch the built-in Android application; I’m trying to send the mail on button click directly without using this application.
25 Answers 25
Send e-mail in Android using the JavaMail API using Gmail authentication.
Steps to create a sample Project:
MailSenderActivity.java:
GMailSender.java:
JSSEProvider.java:
ADD 3 jars found in the following link to your Android Project
And don’t forget to add this line in your manifest:
Just click below link to change account access for less secure apps https://www.google.com/settings/security/lesssecureapps
Run the project and check your recipient mail account for the mail. Cheers!
P.S. And don’t forget that you cannot do network operation from any Activity in android. Hence it is recommended to use AsyncTask or IntentService to avoid network on main thread exception.
Thank you for your valuable information. Code is working fine. I am able to add attachment also by adding following code.
Could not connect to SMTP host: smtp.gmail.com, port: 465
Add this line in your manifest:
You can use JavaMail API to handle your email tasks. JavaMail API is available in JavaEE package and its jar is available for download. Sadly it cannot be used directly in an Android application since it uses AWT components which are completely incompatible in Android.
You can find the Android port for JavaMail at the following location: http://code.google.com/p/javamail-android/
Add the jars to your application and use the SMTP method
100% working code with demo You can also send multiple emails using this answer.
Download Project HERE
Step 1: Download mail, activation, additional jar files and add in your project libs folder in android studio. I added a screenshot see below Download link
Login with gmail (using your from mail) and TURN ON toggle button LINK
Most of the people forget about this step i hope you will not.
Step 2 : After completing this process. Copy and past this classes into your project.
GMail.java
SendMailTask.java
Step 3 : Now you can change this class according to your needs also you can send multiple mail using this class. i provide xml and java file both.
activity_main.xml
SendMailActivity.java
Note Dont forget to add internet permission in your AndroidManifest.xml file
Hope it work if it not then just comment down below.
In order to help those getting a Network On Main Thread Exception with an SDK Target >9. This is using droopie’s code above but will work similarly for any.
You can use AsyncTask as below
Using SMTP is one way to go, and the others have already pointed out ways how to do it. Just note that while doing this, you completely circumvent the built in mail app, and you will have to provide the address of the SMTP server, the user name and password for that server, either statically in your code, or query it from the user.
Another way would involve a simple server side script, like php, that takes some URL parameters and uses them to send a mail. This way, you only need to make an HTTP request from the device (easily possible with the built in libraries) and don’t need to store the SMTP login data on the device. This is one more indirection compared to direct SMTP usage, but because it’s so very easy to make HTTP request and send mails from PHP, it might even be simpler than the direct way.
Mail Application
If the mail shall be send from the users default mail account that he already registered with the phone, you’d have to take some other approach. If you have enough time and experience, you might want to check the source code of the Android Email application to see if it offers some entry point to send a mail without user interaction (I don’t know, but maybe there is one).
Maybe you even find a way to query the users account details (so you can use them for SMTP), though I highly doubt that this is possible, because it would be a huge security risk and Android is built rather securely.
Источник
Android Email App Using Javamail API in Android Studio
In this post we will create an Android Email App.
We will not use the default Android Email Client to send emails instead we will use Javamail API to create our own email sender. And you can also use this App for Email.
So if you are searching Best Email App for Android then try the app created by yourself 😉
Before going through the tutorial you can check the following video to see exactly what you will be creating in this tutorial.
Android Email App – Video
Download Javamail API for Android
- For this Android Email App we will use Javamail API, so before starting our android project download Javamail API from link given below
[download >
- You will get a zip file from the above link. Extract the zip and you will get three .jar files. We will use these .jar files in our android email app project.
Creating Android Email App in Android Studio
- Open Android Studio and create a new android project.
- First we will add the downloaded .jar’s to our project.
- From the left panel click on Android -> Project (see the image below)
android
- Now you will get the libs folder inside projectfolder -> app -> libs . Paste all the three .jar files which you have downloaded above inside the libs folder. (See the image below)
javamail api
- Now go to file -> project structure.
project structure
- Now go to dependencies and from the right click on the green + sign and then click on file dependencies.
file dependencies
- Now go to libs folder and add all the three .jar files (you can see in the image)
adding jar android studio
- Now click on ok, ok and you have added the apis to your project.
- Now come to activity_main.xml and create the following layout.
android email app
- Use the following code for creating the above layout.
- For this android email app we will use gmail to send emails. So create a new java class named Config.java and write the following code.
- You have to write your gmail username and password.
- Now create a new class SendMail.java. It will send our email. Write the following code in this class.
- Now come to MainActivity.java and write the following code.
- Finally add internet permission to manifest.
- Thats it now run your application.
android email app
- Bingo! It is working absolutely fine. You can also download the source code of my project from below.
Get source code of Android Email App
So thats all for this Android Email App tutorial. Leave your comments if you are having any queries or trouble for this Android Email App. Thank You 🙂
Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.
Checkout these tutorials as well:
123 thoughts on “Android Email App Using Javamail API in Android Studio”
Hii thanks for the tutorial its working fine with Gmail but I need to send email using my Yahoo account instead of gmail can you please help me regarding this.
You have to change the values according to yahoo mail
ya i tried using yahoo SMTP details its not working
Ok I will tell you after trying doing it with yahoo
Thanks in advance bro 🙂
hey! it doesnt work on mobile data but works fine on wifi. any solution for this?
It is showing me Message sent in toast but when i check gmail account no mail is received. Please help, i even tried different email accounts.
Secondly, what to do if we wish to send a doc file also as an attached document to the mail?
Please help
check config class.. you have to put your actual gmail username and password there
i will give correct username and password but every time got log mes javax.mail.AuthenticationFailedException…
Allow Access Less Secured App
I also gave permission. Never again
this security setting works for me thanks
Hello sir, I had also the same problem. I put my exact gmail account and password but I don’t still get any mails. Even though it tells me that the mail was sent. Please help me. Thank you
The application works properly, however gmail has a security setting which needs to be addressed.
You need to go to your security settings and turn on “Allow less secure apps:”.
Check out this post here for more details : https://www.drupal.org/node/2080923
I did that but still didn’t receive any mail
can u help me ?
Hi , thanks for this tutorial , but i have question : can i make this app accept any types of emails ( yahoo , hotmail , gmail , ….. ) ?
Same question! I already tried several different ways but I wasn’t successful.
I’m trying to send an Email with the Email address the user’s typing in a text field.
Any help is appreciated!
thanks for the code. but i am getting error in MainActivity.java file in Error:(3, 30) error: cannot find symbol class AppCompatActivity and Error:(31, 36) error: cannot find symbol method findViewById(int). i did all the dependencies in the exact way. waiting for your reply.
Actually this is the problem with your sdk, update your android studio and sdk. Or you can use Activity or ActionbarActivity instead of AppCompatActivity
yeah!! it is working now. can i have your email, so that i can contact you directly?.
Visit about page 😉
Thank u for your code!! Could you also show how to receive messages using JavaMail API, please? I tried to rework your code, but it wasn’t successful:(
Hello , this message is being translated by Google Translate because I do not speak English, I hope you understand .
//Setting sender address
mm.setFrom(new InternetAddress(Config.EMAIL));
//Adding receiver
mm.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
//Setting sender address
mm.setFrom(new InternetAddress(>>email<>Config.EMAIL Reply
not working on my android device even no error in coding……
I implement the same as you have done!
but no message is received in the target email address.
I changed the config file also.
here is the logcat :
01-17 22:19:41.473 12231-12231/polimi.aap.yas.personalhealthrecord E/ViewRootImpl: sendUserActionEvent() mView == null
it says sign in attempt was blocked in my mail
You need to enable POP go to your gmail and from settings enable POP or IMAP
Thank you . Your code and this reply helped me a lot to put the application working. It turns out htat the POP/IMAP was turn off on gmail setting.
thanks for the tut..but when i have my mail and pass stored in config.java .what i want is when user uses my app and wants to send a mail to me, im not getting the mail to my mail ,instead it shows like u got a mail from sv53@gmail.com(this is in config file) to the mail which i entered in receipient field .
when a user send a mail using his mail id, i need to get mail to my sv53 mail id, but how to?
If you are having problems disable you anti-virus and check it again…
Also had to allow less secure app in google.
It works . Thanks man, God Bless You 🙂
It is showing me Message sent in toast but when i check gmail account no mail is received..
Cool tut, I wish I understood Android Studio better but I am just now teaching myself and could use help on a couple projects. I can only imagine how busy you must be, but if you would/could help me just a bit, I sure would appreciate it! If you are interested, please contact me via admin@mohtech.ca
Thank you in advance!
Mike
Hi mate, first of all i want to thanks to you for this tutorial, im having a problem when i click the send buttom, i got the following output:
03-15 08:40:21.396 3801-4071/ar.com.taxiexpress.taxiexpress E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: ar.com.taxiexpress.taxiexpress, PID: 3801
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NoClassDefFoundError: ar.com.taxiexpress.taxiexpress.SendMail$1
at ar.com.taxiexpress.taxiexpress.SendMail.doInBackground(SendMail.java:74)
at ar.com.taxiexpress.taxiexpress.SendMail.doInBackground(SendMail.java:21)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
Could you please helpme with this?
I get the same error. Can anyone help?
Error: java.lang.NoClassDefFoundError: com.sun.mail.util.MailLogger
You should check the gradle file
(App). If you have written duplicate about mail, it would have shown error message like you.
For example, in your gradle file,
If there are more than a line,
compile javax.javamail.5-
dependencies <
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
-> this is two lines about javamail.
So delete one of them. 🙂 i solved the problem in this way
hey how to create new java class as u mentioned like config.java, Mainactivity.java etc on android studio 1.5.1. I am new to android coding.plz help
i got error at this line in main.xml
//Creating SendMail object
SendMail sm = new SendMail(this, email, subject, message);
sm.execute();
showing error as cannot resolve symbol. help me wit this…
I am not able to download your project.
i have some problem
Error:(27, 25) error: package R does not exist
error:cannot resolve symbol variable toolbar,error:cannot resolve symbol variable fab.kindly help in this regards
hi, nice tutorial, i’m got it ^_^
but now i’m to try for receive email, i hope you can help me :’)
thanks
hi i have to design an email client for my project assigned to me can someone help me with the same?
How do i check if email is successfully sent. For example if invalid recipient is used how will i know?
Hello sir, I put my exact gmail account and password but I don’t still get any mails. Even though it tells me that the mail was sent. Please help me. Thank you
I also enabled pop to my Gmail from setting enable pop but still i did not get any mail……please help me to solve this problem
Awsm tuttorial…its working…
in addition to this i want to add extra content with mail(like thanks from our team….) which will be sent to the recipient…and this content shows only when recipient receive the mail….how can i add this extra content with the mail.
please help me to solve this problem
It’s working fine .But whenever i was sending mail getting suspicious mail not allow less security apps ,
how can i achieve that?
Thanks for this blog,It’s helpful!
I want to use a login activity to authentificate the users and after I’ll get a new activity for exemple the inbox and button write new mail!!what can I do for do that idea??thanks in advanced
in my app I have an own text as an EditText which I want to send with an email. How can I add my own text instead of typing one in into the “message field” and send this one via email?
Hi same problem for me also. Whenever I filled all the fields ( receipent, Subject, Body ), it show message sent but I am not able to receive the message.
Please help me. Thanks in advance.
make sure you have enabled the settings in your gmail account
It is working perfectly fine. Thanks a lot. I created a new ID my POP and IMAP both are disabled in gmail settings but still it works.
hii i tried this code but am getting error in code can u please send me your code….. rameshec13@gmail.com
Cannot resolve symbol SendMail in the main activity. Please help! SendMail and execute go red.
SendMail sm = new SendMail(this, email, subject, message);
//Executing sendmail to send email
sm.execute()
I am getting below error please help me.I followed all steps as same in this article.
Источник