js| Send mail
Vishal_donth gave this response on 10/18/2000:
These are are 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 is 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 is 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 a
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 A. If u get no other server which
Supports relaying u can try this
Also.
Use this function in your Servlet to send
Mail by calling the function with the
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 should be delivered
Sessions session = Session.ge Tdefaultinstance (props, null);
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 the internet but not through a
Proxy......or else use a proxy which
Supports SMTP