Here I Come with the Java Code Which can Be used to mail other persons.. Earlier i had written about Oracle Procedure which can send mails. The Java Code which I have made is quite simple and can be easily understood. The code can be extended to incorporate features such as Attaching files. All One has to have is an SMTP host which will send the mail.
People can look for JavaDoc for more Details..
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMailTry {
public void sendMessage() throws AddressException, MessagingException {
Properties props = new Properties();
props.put("mail.smtp.host", "SMTP Host Server Name Here");
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("rakesh_xav@rediffmail.com"));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress("rakesh_xav@yahoo.co.in"));
msg.setSubject("Testing....");
msg.setSentDate(new Date());
msg.setText("Hi All,\nTrying for a Test Mail\n\nRegards,\nRakesh");
Transport.send(msg);
}
public static void main(String[] args) {
SendMailTry sendMail = new SendMailTry();
try {
sendMail.sendMessage();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I am a polyglot programmer, who loves to design & architect solutions and have an opinion on technology. This blog is my space where I share my ideas on technology. They are my ramblings on Tech space in Java & JVM based Languages
Subscribe to:
Posts (Atom)
Java 10 Features
My blog post in JournalDev for Java 10 Features
-
My blog post in JournalDev for Optional (a Value-Based Class)
-
Here I Come with the Java Code Which can Be used to mail other persons.. Earlier i had written about Oracle Procedure which can send mails. ...
-
My blog post in JournalDev for Programming to Interfaces using static methods in Java Interfaces