How to send email from java web application

I have a Java application sitting on Tomcat / Apache.

I have a form that should send email. What is the best way to make this work.

+3
source share
4 answers

Short and dirty copy and paste for sending a simple text mail using javamail here

A small example of sending a text message using a 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);
+4
source

I suppose these threads appeared when you posted your question:

Sending mail from java

How to send email in Java?

Java GMail, Yahoo Hotmail?

+6

You should look at the JavaMail API

Alternatively, you can check out Fancymail , a small library to simplify the use of the JavaMail API.

+5
source

Source: https://habr.com/ru/post/1725932/


All Articles