Can anyone suggest a library for sending emails in Java?
Asked
Active
Viewed 3,778 times
4
-
Yes, https://sourceforge.net/projects/easymail4j/ – Mohamed Ennahdi El Idrissi Dec 27 '16 at 17:15
4 Answers
13
Try Commons Mail. This builds on the Java Mail API but makes it much more simple to use.
Aaron Digulla
- 310,263
- 103
- 579
- 794
8
You may also want to take a look at the Apache Commons Email library. It is featureful and easy to use.
You could do something along the lines of:
import org.apache.commons.mail.SimpleEmail;
...
String[] recipients = {"a@foo.com", "b@foo.com"};
SimpleEmail email = new SimpleEmail();
email.setHostName("mail.myserver.com");
for (int i = 0; i < recipients.length; i++)
{
email.addTo(recipients[i]);
}
email.setFrom("me@apache.org", "Me");
email.setSubject("Test message");
email.setMsg("This is a simple test of commons-email");
email.send();
The sample code is taken from the Commons Email example page, modified to show adding multiple recipients. Hope that helps.
Paul Kuykendall
- 3,087
- 1
- 18
- 16
-
-
you need to authenticate properly, but when that is done, you can use it with gmail – Thorbjørn Ravn Andersen May 12 '09 at 07:15
5
Spring has a mail wrapper layer as well:
http://static.springframework.org/spring/docs/2.5.6/reference/mail.html
Nathan Feger
- 18,596
- 10
- 58
- 70
1
I think it's better to use JavaMail API and you can get some basic knowledge about this from following tutorial Fundamentals of the JavaMail API
Coder
- 1,907
- 3
- 17
- 33