I want my Java application to send out emails to users. But I cant get a good solution.
Now, I got some on Google but they use a SMTP server which I dont have. I was wondering if setting up one on my Linux machine would be easy?
So, I am using mailx now to send out emails but it sends emails from root which is definately not good. Is there any way to send out emails from a proper email using java? like you can do in php and other languages?
Use commons-email to send email from java in a simple, straightforward way (see the docs).
You need an SMTP server always - even in "php and other languages", but perhaps you don't know you need it, because it is bundled in your LAMP package.
One solution is to use google as an SMTP server. Either via your account, or via google apps. Otherwise setting up an smtp server (postfix for example) linux appears trivial, but isn't - you have to take into consideration many things - see this post by Jeff Atwood.
So ultimately, I'd suggest using the options provided by google.
if you'r looking to host your own mail server, then apache james is a pretty good option.
or other solution could be using a third-party mailservers such as gmail or yahoo; and use the JavaMail API to send emails.
If you don't have an SMTP server, Asprin is a send-only SMTP server, which is a pretty good fit. It suffers from the same problem any do-it-yourself SMTP server will, in that it will look more like a Spam source, so using a proper SMTP server used for e-mail should be done if possible.
Related
I have working code to send mail using gmail smtp. It's working on my machine, but when I'm trying to run same code from my office system, then it showing error Unable to Connect SMTP Server. So, I was wondering, is it possible to send mail by bye-passing local/office network ? Any work-around ?
PS: I can't use my corporate email address, since it's internal task.
What you need to do is install a mail server on your machine and use that mail server to send emails. There are a lot of opensource and/or free options available. I have used hMailServer in the past (on Windows7), and it seemed to work for me, just the way I wanted it to. One possible downside of using this approach is that your emails may sometimes end up in the spam folders of your intended recipients.
However, you will need Administrator privileges to install most mailservers.
I'm using Java to send messages from Gmail with Apache Commons Email, but it seems like it doesn't allow me to send messages from an address different from the one that I use to authenticate.
How do you send messages from a different address using Gmail and Java?
Basically, you are looking for an SMTP server which will let you send a message by spoofing the From MIME header. Well, if you can't find a hosted SMTP server online, you can always install one locally on your box. This will allow you to modify the email address of the sender to make it appear as if it is coming from gmail.
As far as I'm aware you can't. That is what is called relaying. Relaying is what the spammers use to send mail pretending to be whoever. Its a security hole. If you want to send as someone else you need to create another account.
How do you send messages from a different address using Gmail and Java?
For gmail, you most likely can't ... for obvious reasons.
In the Java case, whether you can or can't do this depends on the mail server that your Java application connects to. A mail server typically can be configured to allow this, but it has obvious issues so a responsible mail server admin is not going to allow this, except in controlled circumstances.
I have a project with a use case where users should be able to send private messages to other users but this should be integrated with their e-mail box. They should be able to send either private messages or e-mail messages from the same screen.
My thought is to use some kind of open-source e-mail server which will dump the e-mails into MongoDB and then have my Java API pull them out and display them on the interface. And when a user sends an e-mail it is passed by the API to the e-mail server.
Is this a reasonable approach?
If you want your own server (not unreasonable in many cases), check out Apache James - an open-source Java mail server with a plug-in capability. Obviously (!) you can use JavaMail to talk to this, pull messages back etc.
Doesn't Gmail do all of this already? If you want email with chat integration,* that's the first solution that comes to mind. Why reinvent the wheel?
*and about a bajillion other awesome features
JavaMail requires that you specify an external SMTP server when sending mail. I want to have my java app send email directly without having to use an external SMTP server such as postfix or sendmail.
Can anyone recommend a library which provides this kind of functionality?
Ive done some googling and have come up with nothing.
It's not trivial to send mail yourself. To start with, you have to deal with DNS (MX records), queuing, connection management and maybe signing (DKIM). So you wouldn't find any light-weight library like JavaMail to do this.
Your best bet is JAMES,
http://james.apache.org/
I am building a web application that has to be able to do the following:
Send emails to the (external) addresses registered by the users (say, Gmail, Yahoo Mail, etc).
Send/receive emails to local mailboxes that live in the application. These are more "messages" in that sense.
What are the potential open source technologies I could integrate with here? Thanks for your inputs.
So, you want a SMTP server? If you want to have it in Java, then I can suggest to pick Apache James. But in fact every decent SMTP server would suffice. You can just use JavaMail API, or the more convenienced Apache Commons Email which is built on top of JavaMail API, to talk with any SMTP server to send/read emails.
If you didn't already realize, you can also just make use of an existing SMTP server provided by your ISP or the web hosting. In this case only JavaMail or Commons Email would have been sufficient.
While Commons Email will help you get the sending part done, receiving email will require that you access mailboxes via IMAP or POP through the Java Mail API.
Java Mail is a little cumbersome to use, but this Stackoverflow question has a working IMAP sample to help you get started.
There is a JCA (Java Connector Architecture) adapter that makes your Java EE server open port 25 for receiving mails.
http://sourceforge.net/projects/mailra/
A quite old tutorial which is incomplete with some examples for IMAP watching can be found here:
https://community.jboss.org/wiki/InboundJavaMail
A general introduction to JCA can be found here:
http://www.adam-bien.com/roller/abien/entry/a_simple_transactional_file_jca