I have a java web application sitting on Tomcat/Apache.
I have a form which has to send email. What is the best way to get this working.
I have a java web application sitting on Tomcat/Apache.
I have a form which has to send email. What is the best way to get this working.
You should look at JavaMail API (javax.mail)
Additionally, you may want to look at Fancymail, a small library to simplify usage of JavaMail API.
This link might be helpful : http://www.javabeat.net/tips/33-sending-mail-from-java.html
Short and dirty copy-and-paste for sending a simple plain text mail message using javamail here
Tiny example of sending a plain text msg, using custom smtp host:
Properties props = new Properties();
props.put("mail.smtp.host", "your.mailhost.com");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]"));
msg.setRecipients(Message.RecipientType.TO, new InternetAddress[]{new InternetAddress("[email protected]")});
msg.setSubject("Subject Line");
msg.setText("Text Body");
Transport.send(msg);
I suppose these threads did appear when you posted your question:
http://stackoverflow.com/questions/1287440/sending-mail-from-java
http://stackoverflow.com/questions/884943/how-do-i-send-an-e-mail-in-java
http://stackoverflow.com/questions/46663/how-do-you-send-email-from-a-java-app-using-gmail