Here is a program that I wrote using Java to send email the code works using Java API for email that is freely available in the Internet I hope you will find my work useful.
I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details. Thank you.
My mobile number here in the Philippines is 09173084360.
I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Sample Program Output
Program Listing
Sendingemail.java
package sendingemail;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
/**
*
* @author Jake R. Pomperada
* Date April 22, 2018 Sunday
* Bacolod City, Negros Occidental Philippines
*/
class Mailer{
public static void send(String from,String password,String to,String sub,String msg){
//Get properties object
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
//get Session
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from,password);
}
});
//compose message
try {
MimeMessage message = new MimeMessage(session);
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject(sub);
message.setText(msg);
//send message
Transport.send(message);
System.out.println("Email Sending in Java");
System.out.println();
System.out.println("Your Email Sent successfully");
System.out.println();
System.out.println("End of Program !!!");
} catch (MessagingException e) {throw new RuntimeException(e);}
}
}
public class Sendingemail {
public static void main(String[] args) {
//from,password,to,subject,message
Mailer.send("jakerpomperada@gmail.com","yourpassword","jakerpomperada@gmail.com","My first email send in Java",
"This is my first email send using Java !!! \n Thank you for using this Software \n "
+ " Written By Mr. Jake R. Pomperada, MAED-IT");
//change from, password and to
}
}