JSP发送邮件实例
2023-06-13 09:13:45 时间
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"abc@homenetmail.com"
//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
//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"abc@homenetmail.com"
//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
相关文章
- jsp web应用开发_JSP页面
- idea 查看jsp是否被引用_idea 运行JSP后显示源代码是什么情况
- JSP application.log()方法:写入信息到Servlet的日志文件
- JSP jsp:fallback:提示信息标签
- JSP Out.getRemaining()方法:获得缓冲区的剩余空间
- JSP Request.getUserPrincipal()方法:返回java.security.Principal对象
- 用JSP实现MySQL数据库的注册功能(jsp注册mysql)
- 如何使用JSP连接MySQL数据库(jsp如何连接mysql)
- 测试JSP连接MySQL:重塑Web应用(jsp测试mysql连接)
- 数据采用JSP快速修改MySQL数据库中的记录(jsp修改mysql)
- 数据库信息使用JSP显示Oracle数据库中的信息(jsp显示oracle)
- Linux下开发JSP编程指南(linux开发jsp)
- JSP使用MySQL进行留言管理(jsp留言mysql)
- Linux下搭建JSP开发环境(linux配置jsp环境)
- MySQL与JSP无缝连接——实现数据库操作(mysql连接jsp)
- JSP与MySQL实现登录系统(jsp mysql 登陆)
- 长站长如何使用JSP和Oracle搭建网站(jsp oracle的站)
- jsp计数器-jsp文件
- JSP教程(五)-JSPActions的使用下
- 如何使用JSP+MySQL创建留言本(一)
- 如何使用JSP+MySQL创建留言本(二)
- 通用JSP页面jsp入门级文章
- jsp自定义标签实例
- 基于JSP自定义标签使用实例介绍
- JSP页面中如何用select标签实现级联
- jsp中使用javabean实例介绍
- JSP重置按钮清空传入的表单数据实例