This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Android and the fly likes Sending an Email with JavaMail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Mobile » Android
Bookmark "Sending an Email with JavaMail" Watch "Sending an Email with JavaMail" New topic
Author

Sending an Email with JavaMail

Noam Habot
Greenhorn

Joined: Apr 07, 2009
Posts: 5
Hello everyone,
I have imported the JavaMail class into my application with the .jar file found here:
http://www.java2s.com/Code/Jar/wsit/Downloadmail14jar.htm

I would like to find a way to send an email using the JavaMail class.

I have unsuccessfully tried this link:
http://davanum.wordpress.com/2007/12/22/android-send-email-via-gmail-actually-via-smtp/

I've also tried this code:



The problem with it is that it requires the user to pick an email client, and then the user has to send it manually. I want it to send automatically, without notifying the user that the email was sent.

Does anyone have any suggestions?

Thanks,
Noam.
Noam Habot
Greenhorn

Joined: Apr 07, 2009
Posts: 5
I have just found out that the new android sdk is not compatible with the JavaMail external .jar.
Is there a workaround for this? Is there a way to still get it to work?

Thanks,
Noam.
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205

Hi,

Use Java Mail API. This is the standard while working on mail things in Java. Download this API, you will see two jar files in lib activation.jar and another mail.jar (I am not sure about the name for mail.jar). Keep these two jars in classpath and use API.
Everytime prefer to use API which is standard.

Let me know if you get the problem,
Noam Habot
Greenhorn

Joined: Apr 07, 2009
Posts: 5
Thanks for your answer.
I have tried that, and when I import the external library into my application, it tells me:

[2009-04-08 13:49:56 - MyApp] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)

Noam.
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205
Somethig weired....try reinstalling jdk, your IDE
Noam Habot
Greenhorn

Joined: Apr 07, 2009
Posts: 5
I have tried all that but it still didn't work.
Did you ever get it to work?
If so, what android sdk version did you use?
And if you used 1.0+, then could you please put up some code here that we can take a look at?

Thanks,
Noam.
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205
Hi,
I have not worked on Android, but you will get similar code in java on net. There are many samples available on net.
Noam Habot
Greenhorn

Joined: Apr 07, 2009
Posts: 5
That's the problem.
It seems that with Android, the JavaMail class does not work.
Pratik Goswami
Ranch Hand

Joined: Mar 02, 2009
Posts: 136

Hi Noam,

Have you find out the way to send Email with any API from emulator? I tried it with K-9(that was an APK file), but as you mentioned earlier it provides its own GUI to send email when i use intent, user have to send it manually. I tried with Java Mail API also, but no success at all. Please let us know whenever you get the way.

Thanks & Regards
Pratik Goswami


iOS * Android Developer
Joska Lofasz
Greenhorn

Joined: Aug 27, 2009
Posts: 2
Pratik Goswami wrote:Hi Noam,

Have you find out the way to send Email with any API from emulator? I tried it with K-9(that was an APK file), but as you mentioned earlier it provides its own GUI to send email when i use intent, user have to send it manually. I tried with Java Mail API also, but no success at all. Please let us know whenever you get the way.

Thanks & Regards
Pratik Goswami


Hi Pratik and anybody else,

try this: http://nilvec.com/sending-email-without-user-interaction-in-android/

It also explains why Java Mail is not an option for Android.

Regards,
Joska
Steven WangXiangJun
Greenhorn

Joined: Nov 26, 2009
Posts: 2
Noam Habot wrote:Hello everyone,
I have imported the JavaMail class into my application with the .jar file found here:
http://www.java2s.com/Code/Jar/wsit/Downloadmail14jar.htm

I would like to find a way to send an email using the JavaMail class.

I have unsuccessfully tried this link:
http://davanum.wordpress.com/2007/12/22/android-send-email-via-gmail-actually-via-smtp/


Thanks,
Noam.


javamail.jar can't be used in android. Some classes those are not belong to android sdk were imported in the jar .So you have to clean up javamail.jar.


Regards,
Steven
Steven WangXiangJun
Greenhorn

Joined: Nov 26, 2009
Posts: 2
Finally I find the way to send emails on android via javamail.
click Here:http://code.google.com/p/javamail-android/downloads/list

Now,everything is ok!


Steven
Matt Farley
Greenhorn

Joined: Sep 17, 2010
Posts: 1
After searching far and wide for a solution to this .. with the ability to add attachments .. I came across this (and it works!):

[SOLUTION]: http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android
 
GeeCON Prague 2014
 
subject: Sending an Email with JavaMail