Program to Send Email using SMTP
Code:
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SMTPClient
{
public static void main(String args[]) throws Exception
{
String host = "192.168.1.1";//IP address of the receiver
String from = "Administrator";
String to = "Client";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("hi..!");
message.setText("Hi");
Transport.send(message);
System.out.println("Message Send.....");
}}
import javax.mail.*;
import javax.mail.internet.*;
public class SMTPClient
{
public static void main(String args[]) throws Exception
{
String host = "192.168.1.1";//IP address of the receiver
String from = "Administrator";
String to = "Client";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("hi..!");
message.setText("Hi");
Transport.send(message);
System.out.println("Message Send.....");
}}
Download activation.jar and mail.jar.
Paste both the jar files in C:\Program Files\Java\jdk1.7.0_02\jre\lib\ext and
C:\Program Files\Java\jre7\lib\ext.
Set path to the folder where the program SMTPClient.java is saved
Set class path to the folder where program SMTPClient.java is saved.
Compile the program ie.javac SMTPClient.java
Run the program ie java SMTPClient
PREREQUISITE:
FTP service, SMTP service of IIS Server must be installed
The output is always created in location
C:\ Inetpub\mailroot\Drop
0 comments:
Confused? Feel free to ask
Post a Comment