Vishal_donth gave this response on 10/18/2000:
// These are the pakages to be imported from
// Java Mail
// The Java Mail PAckage either be dowloaded
// Seperately
// Or else is Available in the J2sdkee1.2
// (Java Enterprise Edition)
Import javax. mail .*;
Import javax. mail. internet .*;
Import java. util .*;
// This function can be used to send the mail
// With the parameters given to it
// U have to specify the smtp server through
// Which u have to send the mail
// Since I was trying with a homenetmail
// Account I directly sent the mail its server
// For sending this mail u need a mail server
// Which lets u to relay the messages
// Try this thing for sending to
// Www.homenetmail.com account because it lets
// U send
// Mails to the accounts like example try
// Sending it to a "abc@homenetmail.com"
// Account. Create the mail account in homenet
// Mail first. If u get any other server which
// Supports relaying u can try this on that
// Also.
// Use this function in ur Servlet to send
// Mail by calling the function with
// Parameters
Public void sendMail (String toAddr, String subject, String body, String fromAddr) throws RemoteException {
Try {
Properties props = new Properties ();
Props. put ("mail. smtp. host", "mail.homenetmail.com ");
// Here we specify the SMTP server through
// Which the mail shocould be delivered
Session session = Session. getDefaultInstance (props, null );
Message msg = new MimeMessage (session );
Msg. setFrom (new InternetAddress (fromAddr ));
// Specify the From Address
InternetAddress [] tos = InternetAddress. parse (toAddr );
// Specify the To Address
Msg. setRecipients (Message. RecipientType. TO, tos );
Msg. setSubject (subject );
// Specify the Subject
Msg. setText (body );
// Specify the Body
Transport. send (msg );
System. out. println ("Message is Sent ");
}
Catch (Exception e ){
System. out. println (e );
}
}
// U have to run this function on a computer
// Which is directly connected
// To internet but not through
// Proxy... or else use a proxy which
// Supports SMTP