<repo_name>Arangam/DunsMartEmail<file_sep>/src/main/java/com/dnbi/email/DunsMartEmailMain.java
/**
 * 
 */
package com.dnbi.email;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author anil_
 *
 */
@SpringBootApplication
public class DunsMartEmailMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SpringApplication.run(DunsMartEmailMain.class, args);
	}

}
<file_sep>/src/main/java/com/dnbi/email/util/EmailUtils.java
/**
 * 
 */
package com.dnbi.email.util;

import java.io.IOException;
import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

/**
 * @author anil_
 *
 */
public class EmailUtils {
	
	public static void sendEmail() throws AddressException, MessagingException, IOException{
		
		Properties props = new Properties();
		   props.put("mail.smtp.auth", "true");
		   props.put("mail.smtp.starttls.enable", "true");
		   props.put("mail.smtp.host", "smtp.gmail.com");
		   props.put("mail.smtp.port", "587");
		   
		   Session session = Session.getInstance(props, new javax.mail.Authenticator() {
		      protected PasswordAuthentication getPasswordAuthentication() {
		         return new PasswordAuthentication("<EMAIL>", "<PASSWORD>1<PASSWORD>");
		      }
		   });
		   Message msg = new MimeMessage(session);
		   msg.setFrom(new InternetAddress("<EMAIL>", false));

		   msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("<EMAIL>"));
		   msg.setSubject("Reg. GTS Feed File Processing");
		   msg.setContent("Feed File Processing", "text/html");
		   msg.setSentDate(new Date());

		   MimeBodyPart messageBodyPart = new MimeBodyPart();
		   messageBodyPart.setContent("Feed File Processing", "text/html");

		   Multipart multipart = new MimeMultipart();
		   multipart.addBodyPart(messageBodyPart);
		   MimeBodyPart attachPart = new MimeBodyPart();

		   attachPart.attachFile("C:\\AnilKumarLatest\\2021-Learning\\Technical Skills to be imparted.txt");
		   multipart.addBodyPart(attachPart);
		   msg.setContent(multipart);
		   Transport.send(msg);   
		
	}

}
