How to access and extract emails from a SMTP server using APIs - java

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.

Related

Setting up and customizing mail server to store mails in desired way

I'm creating a website(say somesite.com) in Java. A part of the website is: users are provided with e-mail address (username#somesite.com)
and can send & receive emails using the e-mail address and the website.
Now, the problem is to setup a mail server. I tried hMailServer but hMailServer uses its own database tables which is very difficult to
use with the website database design.
Is there anyway to use mail server but store those emails in the way I want
(in website database tables)?
I don't know if this reach your expectation, but take a look at Apache James:
http://james.apache.org/server/index.html

Best way to send an E-Mail from a java Application

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.

Java GroupWise Mail Client

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.

How can I send a confirmation email to users of my application?

I have designed a chat application where different users can create the account, but I do not know how to send a confirmation email to the users. Since I collect their e-mail address in the registration form, how can I send mail to those addresses in Java?
First of all, you need a SMTP server. It's required to be able to send emails. You can make use of the SMTP server associated with your own existing email account, such as the one from your ISP or public mailboxes like Gmail, Yahoo, etc. You can find SMTP connection details at their documentation. You usually just need to know the hostname and the port number. The login details are just the same as from your email account.
You're however restricted to using your own address in the From field of the email and usually also in the amount of emails you're allowed to send at certain intervals. If you'd like to get around this, then you need to install your own SMTP server, for example Apache James, which is Java based, or Microsoft Exchange and so on.
Then, to send an email using Java code, you would need the JavaMail API or the more convenienced Apache Commons Email.
This looks like a good site for you: http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274
Google 'send mail java'
The easiest way of doing this really depends on the environment that your JVM is running in.
If you're running in a standard Linux/UNIX environment and don't want to faff about with extra libraries, then one way is just to "manually" call sendmail (e.g. via ProcessBuilder). As with executing commands generally, you just need to be slightly careful that you don't just pass user input as parameters without screening them.

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