Algorithm for SMTP
Start the SMTP program
Import the package javax.mail .*; and java.mail.internet.*;
Using the following function send the message
InternetAddress("programer@student.com",
"PROGRAMER");
InternetAddress() is used for set the address
msg.setContent("Wish You a Happy Christmas
2008", "text/plain");
Msg.setconet() it is used to set the content
msg.setRecipient(Message.RecipientType.TO,
bhuvangates);-set the message Recipient
msg.setSubject("Greetings");-set the subject of the message
Transport.send(msg);-transport the message
Finally the terminate the SMTP Program
Source code java programming SMTP
import javax.mail.internet.*;
import javax.mail.*;
import java.util.*;
public class Smtpass {
public static void main(String[] args) {
try {
Properties props = new Properties( );
props.put("mail.host", "mail.studentwebsite.org");
Session mailConnection =
Session.getInstance(props, null);
Message msg = new MimeMessage(mailConnection);
Address programer = new
InternetAddress("programer@student.com",
"Bill Gates");
Address bhuvangates = new
InternetAddress("webadmin@studentwebsite.org"
);
msg.setContent("Wish You a Happy Christmas
2008", "text/plain");
msg.setFrom(programer);
msg.setRecipient(Message.RecipientType.TO,
bhuvangates);
msg.setSubject("Greetings");
Transport.send(msg);
}
catch (Exception er) {
er.printStackTrace( );
}
}
}
Output:- CS1404 INTERNET PROGRAMMING LABORATORY
C:\IPLAB>javac Smtpass.java
C:\IPLAB>java Smtpass