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/ .
Related
How can I extract extract emails and attachments using an API from a SMTP (Mail) server?
I was trying to figure out how Posterous worked. I found this open source project but it had no source code.
https://code.google.com/p/os-posterous/
The scope of your question is a little too broad, but yes, there are many APIs available for extracting email content and attachments. It is actually pretty simple to do in most programming languages (though javascript has nothing to do with this). You could look at MailGun, AWS Simple Mail just to name a couple or you could roll your own. You don't need to create an SMTP server for this, just access an email address programmatically, scan the contents of new messages and perform some logic on the content/attachments/etc.
Python: http://docs.python.org/2/library/imaplib.html
PHP: http://us2.php.net/imap
Ruby: http://www.ruby-doc.org/stdlib-2.0.0/libdoc/net/imap/rdoc/Net/IMAP.html
Java: https://javamail.java.net/nonav/docs/api/com/sun/mail/imap/IMAPStore.html
For Posterous I wrote a service in Java which connected to a mail server over IMAP and parsed incoming emails, attachments, etc. The JavaMail framework makes it super simple to do this.
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/
I've been searching for the best way to send an e-mail with an attachment by my java application. I want to use this as an users bug report with logger files. The recipient should be my own e-mail address. I'd prefer the use of an e-mail client.
I tried the following:
Send an e-mail with user authentification like this. I don't want to use this, because the user would need to reveal his e-mail account and password. Furthermore, I'd have to set the properties for every e-mail adress, which is impossible.
Send an e-mail directly to my own e-mail address like this in Listing 16.16 (didnt found an english example). The problem is every e-mail server is using POP authentification nowadays, that means the recipient e-mail server won't accept my e-mail.
Using the mailto URL syntax like this. Doesn't work aswell, because the attachment function isn't working properly in every e-mail client. Best solution so far is to brief the user to add the attachment by himself, after I would put it to his desktop. Or upload the data and add a link to the e-mail body.
The last way I've found is this one. As you could assume this won't work either, because the localhost needs to be connected to the internet and capable enough to send an e-mail.
Hopefully I explained my problem well enough. Is there a different way to send bug reports?
The generally accepted way to get around the problems you describe is to keep all the email logic server side, and then have your application call a web service with the appropriate parameters. It's pretty easy to knock a PHP script / servlet up that will do the job and then send the results on via email, put them in a mysql database or so on.
However, if you can't / don't want to / won't keep this server side, I'd recommend using JavaMail to create a MimeMessage, then using writeTo() to write this to an EML file.
You can then do the usual:
Desktop.getDesktop().open(emlFile);
...which will open the EML file with the default application for handing those files, which is almost always the mail client. Still not foolproof, but if you're determined on sending the email from the client directly I think that's as good as you'll get.
I want to be able to send an email to an email address, and then have it appear on a web page. Is this possible?
My guess is you'd have to write your own email server, something which I am not capable of doing. So I am assuming this won't be possible for me.
But if there is some way it can be done, that would be great. I generally program in Java and use Tomcat as my app server.
No, you wouldn't have to run your own SMTP server. You'd simply need to be able to retrieve mail from a POP3 or IMAP server, using something like the mail client API found in javax.mail.
It would be up to you to decide how much control you'd give to users. For example, who specifies the IMAP settings? Who decides which messages to fetch and display? Maybe that's all pre-configured. Maybe you write full-featured, web-based email client that can send messages as well as retrieve. This is all determined through the design of your web application.
You don't need to write your own mail server. You can use an ordinary (external) mail server and poll its inbox via POP3 or IMAP from your software. This introduces a short delay up to the full poll interval, but that might or might not be acceptable for you.
I can't give you a good tip for a email client lib to use for that, though.
Here is a simple example of sending email trough Google's SMTP server.
Is anyone aware of a way to retrieve and send mails by talking directly to the GroupWise server.
I want to be able to retrieve mail using Java if possible.
I wrote a Outlook Plug-In that retrieved mail out of GroupWise via the Groupwise Outloop Plug-in (If that makes sense).
Then dropped the message in a directory where I retrieved it with a Java App.
The problem is that I cannot add more than one GroupWise account in Outlook and need to.
I had a look at this question, but would like to know if there is a Java API
that will allow me to retrieve/send mail from the GroupWise server in a JavaMail like manner.
Thanks.
GroupWise allows mails to be retrieved using IMAP and POP3 which are standard supported by JavaMail. (And outlook too for that matter)
Sending mail should also be possible using smtp.
If it is for plain email I prefer to use these basic proptocols like smtp, pop3 and imap because they work almost everywhere, anytime and on any platform. They are less feature rich than the proprietary protocols, but that point is often not very relevant since many of these features are only meaningful for a subset of the mailclients out there.