Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java API
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Other JSE/JEE APIs
free smtp server for testing java mail program
Chinna Karuppan
Greenhorn
Posts: 7
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
Can anybody tell me some free smtp server that I can use for
testing
emails...I tried SMTP.GMAIL.COM..CONNECTION TIMED OUT..
The FreeSMTP Server I download doesn't seem to work..
THnks
Tomas Anderson
Greenhorn
Posts: 16
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Did you set the Properties correctly when you attempted to connect to smtp.gmail.com? You may need to add
props.put("mail.smtp.starttls.enable", "true");
The following works for me:
import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SendEmail { public static void sendEmail(String user, String pass, String from, String[] recipients, String subject, String message) throws MessagingException { // Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.auth", "true"); Authenticator auth = new SMTPAuthenticator(user, pass); Session session = Session.getDefaultInstance(props, auth); session.setDebug(false); // create a message Message msg = new MimeMessage(session); // set the from and to address InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(message, "text/html"); Transport.send(msg); } /** * SimpleAuthenticator is used to do simple authentication when the SMTP * server requires it. */ private static class SMTPAuthenticator extends javax.mail.Authenticator { private String username; private String password; public SMTPAuthenticator(String username, String password) { this.username = username; this.password = password; } public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } } }
[ May 27, 2006: Message edited by: Tomas Anderson ]
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JavaMail without SMTP server...
Writing First JavaMail program
Sending mails from someone's address
sending e mail
How To Turn On the IIS SMTP Server?
More...