Java Program to Send Mail


This Program will help to send mail to others using Java Program. The Develop can use this  program to build an application or APP which can send notification when any action happened like task assignment, task removal, comment on task etc.

Please find program below –


Java Program


import javax.mail.*;

import javax.mail.internet.*;

import java.util.*;
import java.util.Date;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class KWMail


public static final void sendMail(String to, String title, String content) {
try {
final String SSL_FACTORY = "";
Properties props = System.getProperties();
props.setProperty("", "");
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.auth", "true");
final String username = "";
final String password = "PASSWORD";
Session session = Session.getDefaultInstance(props,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,

// -- Create a new message --
Message msg = new MimeMessage(session);

// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(to));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
to, false));
msg.setSentDate(new Date());

} catch (MessagingException e) {

public static void main(String[] args){
sendMail("","Hello Test Mail","This is my Test to start one good project.");



Leave a Reply

Your email address will not be published. Required fields are marked *