import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.event.*;
import javax.mail.Authenticator;
import java.net.*;
import java.util.*;
public class servletmail extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
PrintWriter out=response.getWriter();
response.setContentType("text/html");
try
{
Properties props=new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host","smtp.googlemail.com");
props.put("mail.smtp.port", "995");
props.put("mail.smtp.auth", "true");
javax.mail.Authenticator authenticator = new javax.mail.Authenticator()
{
protected javax.mail.PasswordAuthentication getPasswordAuthentication()
{
return new javax.mail.PasswordAuthentication("
[email protected]", "password");
}
};
Session sess=Session.getDefaultInstance(props,authenticator);
sess.setDebug (true);
Transport transport =sess.getTransport ("smtp");
Message msg=new MimeMessage(sess);
msg.setFrom(new InternetAddress("
[email protected]"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("
[email protected]"));
msg.setSubject("Hello JavaMail");
msg.setText("Welcome to JavaMail");
transport.connect();
transport.send(msg);
out.println("mail has been sent");
}
catch(Exception e)
{
System.out.println("err"+e);
}
}
}
how to insert main class in above java code
and how to pass arguments of "from" and "to"