menu


Subscribe to the blog

Social networks

My page on vk.com
My page on Facebook
My page on Google plus
My page on Twitter

Main - Blog - How to send email to JSP Java

Programming Date of creation: Views: 680

How to send email to JSP Java

lesnih.info


Russia

Before you have to be configured Tomcat hosting Installing Apache Tomcat to work in Java JSP

1. Download the library https://javaee.github.io/javamail/ , More you can read about this library here https://wikipedia.org/wiki/JavaMail

2. Add the library to the hosting folder /WEB-INF/lib

3. Create a file for example mail.jsp

4. We paste the code into the file that was created mail.jsp

<%@ page session="false" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ page import="java.util.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>

<%

Properties props = new Properties();
props.put("mail.smtp.host", "---insert smtp server----"); //SMTP Host


Session session = Session.getInstance(props);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("mail@lesnih.info"));
  /// paste the sender's mailbox msg.setSubject("Letter subject");
msg.setText("Message body");
msg.setSentDate(new Date());
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("vitaly@lesnih.info", false));
// we insert the mailbox to whom we send msg.setHeader("Content-Type", "text/plain; charset=UTF-8");
msg.setHeader("Content-Transfer-Encoding", "8bit");
Transport.send(msg);
%>


How to send email to JSP Java
Rating: 5 | Тotal votes: 2 | Please, rate this article




Commets:









    Subscribe to the blog


    Random articles from the blog:


    Installing Apache Tomcat to work in Java JSP

    Installing Apache Tomcat to work in Java JSP
    Topic: Programming

    Tags: java,jsp,сервер,apache tomcat

    Views:265

    Java - TXT Read and write a text document

    Java - TXT Read and write a text document
    Topic: Programming

    Tags: java,txt,write txt,read txt,integration,exchange

    Views:296

    Java XML - Reading XML in a java application

    Java XML - Reading XML in a java application
    Topic: Programming

    Tags: java,xml,reading xml,integration,exchange

    Views:338