vishal_donthgavethisresponseon10/18/2000:
//thesearethepakagestobeimportedfrom
//JavaMail
//TheJavaMailPAckageeitherbedowloaded
//seperately
//orelseisAvailableintheJ2sdkee1.2
//(JavaEnterpriseEdition)
importjavax.mail.*;
importjavax.mail.internet.*;
importjava.util.*;
//Thisfunctioncanbeusedtosendthemail
//withtheparametersgiventoit
//Uhavetospecifythesmtpserverthrough
//whichuhavetosendthemail
//sinceiwastryingwithahomenetmail
//accountidirectlysentthemailitsserver
//Forsendingthismailuneedamailserver
//whichletsutorelaythemessages
//Trythisthingforsendingtoa
//www.homenetmail.comaccountbecauseitlets
//usend
//mailstotheaccountslikeexampletry
//sendingittoa"[email protected]"
//account.Createthemailaccountinhomenet
//mailfirst.Ifugetanyotherserverwhich
//supportsrelayingucantrythisonthat
//also.
//UsethisfunctioninurServlettosend
//mailbycallingthefunctionwiththe
//parameters
publicvoidsendMail(StringtoAddr,Stringsubject,Stringbody,StringfromAddr)throwsRemoteException{
try{
Propertiesprops=newProperties();
props.put("mail.smtp.host","mail.homenetmail.com");
//HerewespecifytheSMTPserverthrough
//whichthemailshouldbedelivered
Sessionsession=Session.getDefaultInstance(props,null);
Messagemsg=newMimeMessage(session);
msg.setFrom(newInternetAddress(fromAddr));
//SpecifytheFromAddress
InternetAddress[]tos=InternetAddress.parse(toAddr);
//SpecifytheToAddress
msg.setRecipients(Message.RecipientType.TO,tos);
msg.setSubject(subject);
//SpecifytheSubject
msg.setText(body);
//SpecifytheBody
Transport.send(msg);
System.out.println("MessageisSent");
}
catch(Exceptione){
System.out.println(e);
}
}
//Uhavetorunthisfunctiononacomputer
//whichisdirectlyconnected
//tointernetbutnotthrougha
//proxy......orelseuseaproxywhich
//supportsSMTP
vishal_donthgavethisresponseon10/18/2000:
//thesearethepakagestobeimportedfrom
//JavaMail
//TheJavaMailPAckageeitherbedowloaded
//seperately
//orelseisAvailableintheJ2sdkee1.2
//(JavaEnterpriseEdition)
importjavax.mail.*;
importjavax.mail.internet.*;
importjava.util.*;
//Thisfunctioncanbeusedtosendthemail
//withtheparametersgiventoit
//Uhavetospecifythesmtpserverthrough
//whichuhavetosendthemail
//sinceiwastryingwithahomenetmail
//accountidirectlysentthemailitsserver
//Forsendingthismailuneedamailserver
//whichletsutorelaythemessages
//Trythisthingforsendingtoa
//www.homenetmail.comaccountbecauseitlets
//usend
//mailstotheaccountslikeexampletry
//sendingittoa"[email protected]"
//account.Createthemailaccountinhomenet
//mailfirst.Ifugetanyotherserverwhich
//supportsrelayingucantrythisonthat
//also.
//UsethisfunctioninurServlettosend
//mailbycallingthefunctionwiththe
//parameters
publicvoidsendMail(StringtoAddr,Stringsubject,Stringbody,StringfromAddr)throwsRemoteException{
try{
Propertiesprops=newProperties();
props.put("mail.smtp.host","mail.homenetmail.com");
//HerewespecifytheSMTPserverthrough
//whichthemailshouldbedelivered
Sessionsession=Session.getDefaultInstance(props,null);
Messagemsg=newMimeMessage(session);
msg.setFrom(newInternetAddress(fromAddr));
//SpecifytheFromAddress
InternetAddress[]tos=InternetAddress.parse(toAddr);
//SpecifytheToAddress
msg.setRecipients(Message.RecipientType.TO,tos);
msg.setSubject(subject);
//SpecifytheSubject
msg.setText(body);
//SpecifytheBody
Transport.send(msg);
System.out.println("MessageisSent");
}
catch(Exceptione){
System.out.println(e);
}
}
//Uhavetorunthisfunctiononacomputer
//whichisdirectlyconnected
//tointernetbutnotthrougha
//proxy......orelseuseaproxywhich
//supportsSMTP
|