Implement SMTP request in Java using socket | SMTP in java Coding

SMTP-Simplified Mail Transfer Protocol .SMTP is used to sent the mail. SMTP it has some proper standard like form address, to address like ordinary post. SMTP it has From address, To Address, Subject, message content

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
Implement SMTP request in Java using socket  SMTP in java Coding

Implement SMTP request in Java using socket  SMTP in java Coding

Related post