We can send mail through JavaMail Api through java code.I have read somewhere and thought of sharing with everyone.
For using this code you need to JavaMail Api.
//get mail session Properties props = new Properties(); props.put("mail.smtp.host","localhost"); Session session = session.getDefaultInstance(props); // create the messge. MimeMessage message = new MimeMessage(session); message.setSubject("Vinay first Mail"); Message.setText("Vinay mail text "); //address the message InternetAddress addfrm = new InternetAddress("[email protected]"); message.setFrom(addfrm); InternetAddress addto = new InternetAddress("[email protected]"); message.setRecipient(Message.RecipientType.TO,addto); //send message Transport.send(message);
Update
Send email in text and html format Text and HTML format