How to automatically get new mails from gmail account using java? - java

I know my question is more likely to be discussed rather than really answered (because it's very large), but I need some elements and "advices" to really get started, sorry for that.
So I've got a java program which has to analyse some URLs, I've finished this part. For the moment, the user has to enter manually the link into my program, then the link is analysed.
Now I have to retrieve automatically those links, which will be sent to me via e-mail. (In a special Gmail inbox created for that purpose)
So I need to :
Let my Java program "listen" to my inbox
Extract the link of any new mail in order to analyse it
There are many problems, according to the way I choose to access to my inbox (POP3, GMail API...), according to the frequency my application would check the inbox, maybe there would be authentification problems... Even how to let my application run as a "daemon"...
And I really don't know how to get started, which choices to make etc.
Any help is welcome of course, if you have any documentation or else. Thank you in advance.

You have several ways of doing this.
I suggest you using Java Mail, that has a simple and useful API.
You have some documentation and examples in this URL:
https://java.net/projects/javamail/pages/Home#Samples
Look at the class monitor (very bad name!!!) inside the examples. This class monitor a mail box for new emails.

Related

Troubleshoot log-in issue

In interview, I have been asked that "A user tries to log-in to a website with proper credentials and he is just taken to blank page. How would you troubleshoot that?"
I have basically talked about to go and check the splunk logs with X-request id. Make sure the entire URL request is correct, and check the error message.
But I am not sure the exact answer of this question? Could you help me to answer this question perfectly?
There is no perfect answer, because it depends on what web infrastructure they are using, and if they are leveraging Splunk at all. In most cases, an investigation will not start with a request-id. Someone will come to you and say 'find it'. I'd say the best way to answer this question is by asking questions.
IF (big if here) they are using splunk, then it's something like this:
Questions to ask:
What is the time frame this happened in?
is there are user / ip associated with this, or is that what you're looking for?
what system did this occur on? (assuming they have more than a single web front end. iis, apache, blah blah)
Solution:
Use Splunk to search web data any failed login events during the time window mentioned, and provide a report of user/hosts/ips to the SME / system owner or requester.

Allow app to communicate with web domain

I have a domain that is user posts based. I plan to create a user posts based app like 9gag. I need the app to be able to communicate and fetch data hosted from my domain.
Things I need the app to do:
1) Allow users to post pictures though the app.
2)Allow users to leave comments through the app.
3)Allow users to leave 'likes' though the app.
I want the data to be stored on my domain, while when a user opens the app, the app will fetch this data from the domain and display it for the user. How can I make my app communicate with the domain?
Thanks!
The best way to do this would be to implement an API on your domain that your app can send requests to. I cannot explain all this in detail here because it would require a lot of space and a full blown tutorial, but I can tell you what to research and what to implement to make this happen.
First off you need to create an API for your app to send requests to. I suggest a "RESTful" api as they are pretty strait forward to the average programmer. Here is a good video that explains what an API is and a little bit of how they are typically implemented. https://youtu.be/7YcW25PHnAA
After you have an API setup, you have "encode" the information so that it is easy to parse once your app has a hold of all that information. To do this we use a "data-interchange format". One of the big ones being used today is JSON, see their website to learn more here: http://www.json.org/ JSON is pretty strait forward and easy to understand if you have a concept of what Programming: objects, strings, arrays etc are.
Ok so you have gotten your information from the server, you have parsed it from the JSON you got, and displayed all your content... now, what do you do if your user give a thumbs up or comment on something? This is also implemented via the API, this part should be easiest for you, it involves wrapping up the required data (Content id, user id, what they did [ie liked the content]) and send this via a http request, just like how you got your information in the first place, but instead of reading the data response, now we are just sending the HTTP request from the app, and we don't care what happens next (on the app level) its up to the server to record the data from the HTTP request.
I would highly suggest looking up how to create API and look through some tutorials... there are a lot of tutorials out there that want you to modify the HTACCESS file on the server, this is really necessary (Boy I hope I don't get crucified for saying that; fellow Stack Overflow Citizens, if you disagree, please explain your reasoning) Obviously for a large mainstream website, the whole HTACCESS file might be a good idea, but for a beginner, I don't think it is really needed.

Is there a way to send clients or users Logcat or exceptions to me?

Hí,
I'm doing my second App, and The second one is a little bit complex, it's backup tool.
In some devices works perfect in others not.
I would like if is there a way to do my own Exceptions catcher to my server or log cats or smth, and receive them, and known if my app needs some fix or not etc.
Greetens and thanks
David
As pointed out, you can use ACRA. The site states:
Acra catches exceptions, retrieves lots of context data and send them
to the backend of your choice.
and that is what you seem to need. The Quick Setup Guide is there on the homepage itself.
You can also look into BugSense which you can use as a back end for your ACRA.
If you are using ACRA, you can use BugSense as your backend.
The only change you need to do is specify in formUri BugSense's url
and your API key:
#ReportsCrashes(formUri =
"http://www.bugsense.com/api/acra?api_key=YOUR_API_KEY", formKey="")

Create an E-Mail and view it before sending

I'm searching the web for days now and didn't find any solution. Also there is no solution in my other question about OLE.
Is it possible, to create an E-Mail for Outlook, fill in stuff (body, subject) and show it for the user to view so he can click send hisself?
If it is possible, how. What APIs/Frameworks or Libraries are ther which support this. And ist der an SSCCE to view?
I can't get SWT (eclipse) to work. Not with the newest version, it always shows an error. I use x64 and Outlook 2013. To view my error watch here: How to create an E-Mail in Outlook and make it visible for the User
I hope somebody knows how this could be done, or just give me the answer it's not possible, so I can stop searching.
Thank you.
Edit
I have to use Outlook, because it's the E-Mail Tool used in my company. And I don't want to send it automatically but the user needs to view the E-Mail and send it manually.
Email is just a text. Sometimes it is formatted as a simple HTML page. So, you can use any HTML viewer to view email content. If you are working on desktop application note that Swing components support simple HTML (version 1.0 or so). If you are working on web based application you can show email text into div, iframe etc.
If you want to call default email client from your java application use Desktop.mail(URI). Take a look on this discussion.
BTW is seems we are using different google. I typed "call email client from java app" and immediately found the mentioned SO discussion.
EDIT
I think that your question was not exactly correct. Outlook is just one of various email clients. Well, very popular. But still one of... It is not guaranteed that it is installed on user's machine. So, you cannot require from java application to run Outlook. However you can run default email client.

Launching a website from within a program, and inputting data to specific fields

Although I've been programming for a few years I've only really dabbled in the web side of things, it's been more application based for computers up until now. I was wondering, in java for example, what library defined function or self defined function I would use to have a program launch a web browser to a certain site? Also as an extension to this how could I have it find a certain field in the website like a search box for instance (if it wasnt the current target of the cursor) and then populate it with a string and submit it to the server? (maybe this is a kind of find by ID scenario?!)
Also, is there a way to control whethere this is visible or not to the user. What I mean is, if I want to do something as a background task whilst the user carries on using the program, I will want the program to be submitting data to a webpage without the whole visual side of things that would interrupt the user?
This may be basic but like I say, I've never tried my hand at it so perhaps if someone could just provide some rough code outlines I'd really appreciate it.
Many thanks
I think Selenium might be what you are looking for.
Selenium allows you to start a Web browser, launch it to a certain website and interact with it. Also, there is a Java API (and a lot of other languages, by the way) allowing you to control the launched browser from a Java application.
There are some tweaking to do, but you can also launch Selenium in background, using a headless Web browser.
as i understand it you want to submit data to a server via the excisting webinterface?
in that case you need to find out how the URL for the request is build and then make a http-call using the corresponding URL
i advice reading this if it involves a POST submit

Categories