Android - JavaMail with Gmail ID - java

I'm writing an application which will need to be able to receive email from a specific account (in this instance Gmail) and get the unique Gmail ID of each message in order for it to create a link to that message for future reference.
All of this can be done in Java using the JavaMail API and the GmailMessage class and connecting via 'gimaps'. However this API doesn't compile when imported into my Android application - Unable to execute dex: Multiple dex files define Lcom/sun/mail/iap/AString I get different variations of these depending on which jars I try to import (pop3, imap, gimap etc)
Searching around it seems I need to use one of the JavaMail android ports however none of them have the ability to grab the Gmail unique message id.
So my question is does anyone know of a way to do this on Android, using either the official JavaMail API (if that's possible) or using on the various ports?
Thanks.
EDIT:
Thanks, actually I've got it partially working using a port found here https://code.google.com/p/java-gmail-imap/ however it crashes when trying to grab the body of text from the email. I know this is due to the same files missing that are corrected in this port https://code.google.com/p/javamail-android/
I've checked out the java-gmail-imap code into eclipse to try and add the missing classes from the android port but everytime I export I get java.lang.NoClassDefFoundError: com.google.code.javax.mail.Session
Opening the jar file this class is present.. anyone know what I could be doing wrong?

Unfortunately, Android isn't Java, so some of this stuff might not work.
Based only on the error message, it looks like you've tried to import multiple jar files that define the same class (com.sun.mail.iap.AString). Check that you don't have more than one copy of JavaMail in your application.

I managed to get this working using the library found here and changing some of the imports to the myjava.* imports from the Android Java Mail port.

Related

Using two Google APIs with the same application

I have an application which connects to Google Drive API.
Now I have to add another function which requires the Google Directory API.
I granted the necessary permissions and enabled the new API in my project.
However I'm still getting this error:
"message" : "Access Not Configured. Admin Directory API has not been
used in project 594418282793 before or it is disabled. Enable it by
visiting
https://console.developers.google.com/apis/api/admin.googleapis.com/overview?project=594418282793
then retry. If you enabled this API recently, wait a few minutes for
the action to propagate to our systems and retry."
The problem is that the URL in the message gives me an error; apparently the project ID is invalid.
This is the error:
There was an error while loading
/apis/dashboard?project=594418282793. You are missing at least one of
the following required permissions:
Project
resourcemanager.projects.get
Check that the project ID is valid and you have permissions to access
it.
I have no idea what is the cause of this mismatch, why the project ID provided in the error message doesn't seem to exist, and where else should I enable the second API in my application.
Any ideas would be much appreciated.
I think you have miss understood how the credentials.json works.
Access Not Configured.
Means that the credentials you have loaded for this client has not been setup for the api you are trying to connect to.
When you create a project on Google developer console this is to give google information about your application as a whole and what it is designed to do. You should enable both apis in the single project.
Once that is done create your Oauth credentials as you did before this credential file will then be able to connect to both apis .
googel developer console
Left hand menu click credentials then button on the top says create credentials
Once you have created it click the arrow to download you can download the file anytime

What username and password is needed for JavaMail API?

I'm trying to learn how to send an email using a Netbeans application. Whenever I run the application, I keep getting the following error:
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted.
I got code from two different sources (specified below) and both give the exact same error. I used the correct .jar files, and the code was copied exactly as shown in the tutorials, but neither works. I also tried using my proper Gmail credentials (made sure they were 100% correct) and I still get the error.
What I want to know is:
What do I use as username and password? (are there predefined ones I need to obtain or do I need to create them, and if so how?)
Sources:
This one does not specify a password anywhere at all: Email: How to send email using java Netbeans [Tutorial] - YouTube
This one specifies a password as String pass = "****"; which I changed to String pass = "pass123";: Send email using Java (in NetBeans)
Okay I found out the answer. The thing that was causing the error was:
Gmail actually prevented the application from sending the email from the Java application because it read it as a "Less secure app" trying to sign in to my account.
A few relevant changes and the application works now
I hope you have downloaded the required jars to fulfill Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files.
Now when you want to connect with Gmail account programmatically then you have to enable the allow less secure apps. You can do that by using the following link.
If you access more times repeatedly then the access can be blocked by Google and even Google will intimate with Critical Security Alerts
Allow Less secured Apps

How to access mocked email in Play 2.4.x

I'm currently trying to write some test for a small play (2.4.0) application. I need to get a link that I send in a mail (generated with database content), but I didn't find how to get access directly to the mocked email.
I know from another answer that there was a way to do it for the play 1.x versions but I didn't find any equivalent. Any idea?

Is it possible to get e-mail source using JavaMail?

I use JavaMail API to download mails via IMAP. I want to save them locally, in files. I have a DB, but I only want to store some meta-data in it (like mail file location).
Is there a possibility, using the JavaMail API, to get the actual source of an e-mail? Like in Outlook via context menu on a mail in a list and 'View Source'.
Thanks,
Daniel
After some more API reading I've found a solution.
javax.mail.Part#writeTo(OutputStream)
does the thing.

How to check DKIM signature of incoming email in Java Google App Engine

I am looking for a way to validate the DKIM signature of the incoming email.
I know how to do it in Java SE but it will use classes like javax.naming.directory.DirContext to get data from DNS server and this class is not white listed in App Engine.
Any idea how to communicate with DNS form Google App engine?
There is a blog post that says:
Once you've configured DKIM, just send
an email from your Google Apps account
to:
dkim#dkim-test.appspotmail.com
within minutes, you should get back an
email that says "PASS" or "FAIL". If
your test passed, you're all set!
I tried it and it works!
It seems like a Google App Engine Application. How is it done?!
I'm the author of the dkim-test app. Unfortunately I did not actually find a native way to do DNS queries in AppEngine. There's a feature request in the AppEngine issues tracker here:
http://code.google.com/p/googleappengine/issues/detail?id=354
The way I got around this for dkim-test was to do a HTTP GET request to http://whatsmyip.us/dns_txt.php?host=google.com (where google.com is the host I want to retrieve TXT records for).
Obviously there are some down sides here. dkim-test is entirely dependent on whatsmyip.us to work, should that service go down or they decide to block dkim-test, then it would break. Things would also break if they changed the format of the response.

Categories

Resources