3

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.

Ankur
  • 50,282
  • 110
  • 242
  • 312

3 Answers3

6

I suppose these threads did appear when you posted your question:

Sending mail from java

How do I send an e-mail in Java?

How can I send an email by Java application using GMail, Yahoo, or Hotmail?

Community
  • 1
  • 1
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
5

You should look at JavaMail API

Additionally, you may want to look at Fancymail, a small library to simplify usage of JavaMail API.

Srini
  • 1,626
  • 2
  • 15
  • 25
sfussenegger
  • 35,575
  • 15
  • 95
  • 119
  • 1
    I remain mystified that `javax.mail` hasn't yet made it into JavaSE, but things like JAX-WS and SOAP have. It's damned peculiar. – skaffman Dec 17 '09 at 08:51
4

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("mail@from.com"));
    msg.setRecipients(Message.RecipientType.TO, new InternetAddress[]{new InternetAddress("mail@to.com")});
    msg.setSubject("Subject Line");
    msg.setText("Text Body");
    Transport.send(msg);
Joel
  • 29,538
  • 35
  • 110
  • 138