It might be a little too old, but I just managed to get javamail and sendmail to work together. It is actually very simple, and I was stupid because I did not do it faster ...
Let's ignore sendmail a bit. How can we send an email through javamail? There are tons of tutorials online, but here's how to do it:
- Create a session with the appropriate authenticator;
- Create a MimeMessage object (here, where you add all recipient addresses);
- Call Transport.send () with your message.
What if your SMTP server sends emails to up to 100 recipients (for example, mine)? This is when sendmail comes into play. You can think of sendmail as your own SMTP server. Therefore, install it first. If you are using Ubuntu (like me), just do:
sudo apt-get install sendmail
Installation completes pretty quickly. After that, sendmail is ready to use. I did not set up any type of authentication at all, but it is probably a good idea if your server has a public IP address on the Internet. Now, instead of pointing your Java code (which javamail uses) to your SMTP server, just point it to localhost (or to some other computer that you just installed sendmail).
You can even test your sendmail installation using a regular mail client (thunderbird, Outlook, Windows Mail, or any other boat on your boat). Just configure your SMTP server on the computer where sendmail is installed. Guess what? He works!
Just do not use this to send letters to the whole world ...;)
source share