您正在使用 IPV4 [3.138.138.144] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
[公益]保护绿色环境,构建和谐社会       悟空收录网      

【腾讯云】 爆款2核2G3M云服务器首年 61元,叠加红包再享折上折      
[公益] 地球是我家,绿化靠大家      
2024年 劳动节 014
2024年 端午节 054
2025年 元 旦 259
2025年 春 节 287
 
您现在的位置:首页 >> JSP >> 内容
本类新增
本类热门
JSP发送邮件实例
内容摘要: vishal_donthgavethisresponseon10/18/2000://thesearethepakagestobeimportedfrom//JavaMail//TheJavaMailPAckageeitherbedowloaded//seperately//orelseisAvailableintheJ2sdkee1.2//(JavaEnt......
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

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:jsp实现登录验证的过滤器

 

下一篇:使用JSP读取客户端信息

发布日期:2022/9/27
手机扫二维码直达本页
发布时间:15:34:00
点  击:9
录  入:齐天大圣
相关文章
Baidu
YiJiaCMS 7.3.8 build231228(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,Cloudflare提供加速防护
运行时间载入中.....