In this video we are going to learn how to send email using java and gmail without less secure app 2023 step by step.



<project xmlns="" xmlns:xsi=""







        <!-- -->

        <!-- -->



import jakarta.mail.*;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;

import java.util.Properties;

public class GEmailSender {

    public boolean sendEmail(String to, String from, String subject, String text) {
        boolean flag = false;

        //smtp properties
        Properties properties = new Properties();
        properties.put("mail.smtp.auth", true);
        properties.put("mail.smtp.starttls.enable", true);
        properties.put("mail.smtp.port", "587");
        properties.put("", "");

        String username = "youremailusername";
        String password = "jfrgaungfubodnni";

        Session session = Session.getInstance(properties, new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);

        try {

            Message message = new MimeMessage(session);
            message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setFrom(new InternetAddress(from));
            flag = true;
        } catch (Exception e) {

        return flag;



public class App {
    public static void main(String[] args) {

        GEmailSender gEmailSender = new GEmailSender();
        String to = "[email protected]";
        String from = "[email protected]";
        String subject = "Second: Sending email using GMail";
        String text = "This is a example email send using gmail and java program with out less secure app";
        boolean b = gEmailSender.sendEmail(to, from, subject, text);
        if (b) {
            System.out.println("Email is sent successfully");
        } else {
            System.out.println("There is problem in sending email");




checkout out preminum courses: