Java J2ME JSP J2EE Servlet Android

Send email: Java

Java has a separate package for email that is java mail api. We can use this api to send and receive emails using java. Here is a java method to send email using java mail api.

public static void sendMail(String from, String to, String subject,
String textBody, String htmlBody, String host)
throws AddressException, MessagingException {
Properties props = System.getProperties();

props.put("mail.smtp.host", host);

Session session = Session.getInstance(props, null);

MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(subject);
message.setText(textBody);

message.setContent(htmlBody, "text/html");

Transport.send(message);
}

I think it'll help you. If you have any question on java email just add as comment. I'll try to answer..