Need MCA Or College Project Contact Us: +91 9437911966 (Whatsapp) Students Tutorial

How to send mail in Java

Two jar file needed for send mail

Here we using 1 files for send mail in Java using Gmail SMTP:

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class test {
public static void main(String[] args) {
String to="";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("", "");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("","password");//Put your email id and password here
//compose message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(""));//change accordingly
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
//send message
System.out.println("message sent successfully");
} catch (MessagingException e) {throw new RuntimeException(e);}