java program to check periodically ms outlook for new mail - java

I need the solution for the below problem in Java -
On arrival of new mail in ms outlook for a particular email id, there should be a web service get executed automatically.
is it possible? please help!

You can do that using java mail. You will need to find the configuration details but a standard code snippet for this would be something like below. I copied the code snipped from here. Thos official javamail link has a pretty decent set of examples (ie. how to read attachments).
For storing the email as a file to a folder, you can apache FileUtils. Write the email to a file and copy it to a folder that you desire.
There is one more interesting resource

Related

Sending mail using java : file is not getting attached from local system

I am developing a web application using Oracle ADF and jdeveloper11.1.2.4. In that I have a form to send a mail with required input fields. Example toAddress, ccAddress and attachemnt Location(input text field). I am sending mails using java mail api. I got this information from the post
Mail using java
My problems is with attachment file. I am able to send an email successfully with attachment if I gave a location of the file that is on server(on which my application has deployed).
Beacause my application is web application user can access through internet. If am trying to add a location of the file that is in local system(Other than server) then file is not getting attached and mail is not getting send.
I am unable to attach a file from other than server.
Please help me. How do I achieve this. User should be able to attache a file from his/her system(local system).
First upload your file to server directory
see- http://www.awasthiashish.com/2014/08/uploading-and-downloading-files-from.html
Then provide a path when sending mail
see-http://www.awasthiashish.com/2013/04/gmail-integration-with-oracle-adf-using.html
First you will have to upload the file to the server and then attach that file in your email as JavaMail will need an absolute path on your current server.
PS: If you are sending emails using java I would highly recommend looking at Apache Commons email library https://commons.apache.org/proper/commons-email/userguide.html
It will make your life a lot easier.

Java outlook integration

I have a program that must 'prepare' emails for me. When the email is prepared, it should show in outlook (or an other email client - default user mail client).
I have used the Desktop.getDesktop().mail approach, but I'm very limited with the options. (I cannot set the high importance). An other option I've tried is JavaMail. But here the mail will be send instead of opened in the email client. (same for Apache POI).
An other option I've considered is to write a .msg/.eml file and open it, but this must be done manually (via java I get a 'file not found' error or an error regarding privileges).
Does anyone know other options or other approaches I might have missed / overlooked?
You can make use of moyosoft's connector to access outlook functionality from java. Please refer to below url's for more details on this.
http://www.moyosoft.com/joc/
http://www.moyosoft.com/joc/getstarted/

Java: adding attachment to the mail client launched using getDesktop().mail(URI)

In Java, how to launch the mail client along with the given file as its attachment - particularly using the method Desktop.getDesktop().mail(URI)
I am using Windows 7 and want to launch MS Outlook.
It is a good question.
Indeed the URI that sent as a parameter to method desktop.mail(URI) allows setting to, cc, bcc, subject, body and does not allow setting attachments. (see http://www.ietf.org/rfc/rfc2368.txt)
However attachments are actually specially formatted fragments of email body. Please read this for more details: http://techhelp.santovec.us/decode.htm.
This means that you can encode your binary attachment using Base64 and create email body that already contains the attachment of any generic file. I personally have not tried this but I believe it must work. Good luck.
As far as I know, it is unfortunatly not possible to specify any attachment using Desktop.mail(URI).
I've tried AlexR suggestion. It doesn't work if the file is too big because of the restriction of the number of characters in the URI.
However, it is still possible using JMAPI, though it only works on x86 platforms.
The ultimate way to make it work is using the JavaMail API, but it forces you to create your own GUI and to set the SMTP server configuration.. which is not pretty user-friendly.
If anyone as other suggestions, i'd be glad to know them.

Auto Generated Mail

Perhaps this kind of question comes under not to ask category but for the sake of application I have to ask.So pardon me.
At the time of Log in,I found that(suppose)If I am unable to remember my password,then I have to put my email-id then an auto generated reply come from that's hosted site with
a new link for generating another new password or
simply sending password(that means password isn't encrypted,I guess) in reply.
watching the source code it's hard to predict,but I want to know(if they are using jsp) then which protocol is used for this auto generated mail what are the other things to remember to achive this, while I'm also making an application for auto generated mail.
I have done this using javax.mail api in java
google for sending mail using java...
define content of mail in template or resource file and send mail whenever user clicks on forgot password link.
It is using SMTP protocol only.

Is there a library for reading /var/spool/mail/ files?

How does one parse the mail files generated on a Linux system using Java? I mean, I want to be able to extract the From, To, Timestamp and Subject of the various emails inside the file. Any suggestions?
javax.mail.internet.MimeMessage.parse(InputStream)
it's protected but you can subclass it to use the method. However, the file format is quite simple, if you just want some headers, why not parse it on your own?
Those files belong to the Mail Transfer Agent and maybe the user's mail client. Other programs should tread very softly or better yet keep out altogether. Or is your program a mail client?
The "clean" way to do this would be to open up an SMTP or IMAP connection to the mail server / MTA and ask it for pieces of mail on behalf of your user, using his credentials that he gives you.
There's a Java mail API for this that knows how to do this well: http://java.sun.com/products/javamail/ .

Categories