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: 602

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:


    Post java - Send POST request in Java

    Post java - Send POST request in Java
    Topic: Programming

    Tags: java,post,php,integration,exchange

    Views:326

    Redirect to Apache Tomcat - htaccess

    Redirect to Apache Tomcat - htaccess
    Topic: Programming

    Tags: java,jsp,server,apache tomcat

    Views:346

    Mysql Java - UPDATE - update data in Mysql

    Mysql Java - UPDATE - update data in Mysql
    Topic: Programming

    Tags: java,mysql,update

    Views:212