欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

邮件发送简单例子-jsp文件

程序员文章站 2024-02-26 15:57:46
mailexample.jspjsp javamail example </title>...</div> <div class="content"> mailexample.jsp<br><br><html><br><head><br><title>jsp javamail example </title><br></head><br><br><body><br><br><%@ page import="java.util.*" %><br><%@ page import="javax.mail.*" %><br><%@ page import="javax.mail.internet.*" %><br><%@ page import="javax.activation.*" %><br><br><%<br>string host = "yourmailhost";<br>string to = request.getparameter("to");<br>string from = request.getparameter("from");<br>string subject = request.getparameter("subject");<br>string messagetext = request.getparameter("body");<br>boolean sessiondebug = false;<br><br>// create some properties and get the default session.<br>properties props = system.getproperties();<br>props.put("mail.host", host);<br>props.put("mail.transport.protocol", "smtp");<br><br>session mailsession = session.getdefaultinstance(props, null);<br><br>// set debug on the session so we can see what is going on<br>// passing false will not echo debug info, and passing true<br>// will.<br>mailsession.setdebug(sessiondebug);<br><br>// instantiate a new mimemessage and fill it with the<br>// required information.<br>message msg = new mimemessage(mailsession);<br><br>msg.setfrom(new internetaddress(from));<br>internetaddress[] address = {new internetaddress(to)};<br>msg.setrecipients(message.recipienttype.to, address);<br>msg.setsubject(subject);<br>msg.setsentdate(new date());<br>msg.settext(messagetext);<br><br>// hand the message to the default transport service<br>// for delivery.<br>transport.send(msg);<br><br>out.println("mail was sent to " + to);<br>out.println(" from " + from);<br>out.println(" using host " + host + ".");<br><br>%><br></table><br></body><br></html><br><br> </div> <div class="info-pre-next"> <p> 上一篇: <a href="/article/2510505.html"> 决策树原理实例 </a> </p> <p> 下一篇: <a href="/article/2510507.html"> MySQL的Replace into 与Insert into on duplicate key update真正的不同之处 </a> </p> </div> <div class="wz_tuijian"> <p> 推荐阅读 </p> <ul> <li> <a href="/article/2510506.html" target="_blank" title="邮件发送简单例子-jsp文件"> <h2> 邮件发送简单例子-jsp文件 </h2> </a> </li> <li> <a href="/article/2505231.html" target="_blank" title="JSP发送邮件实例"> <h2> JSP发送邮件实例 </h2> </a> </li> <li> <a href="/article/2494308.html" target="_blank" title="phpmailer简单发送邮件的方法(附phpmailer源码下载)"> <h2> phpmailer简单发送邮件的方法(附phpmailer源码下载) </h2> </a> </li> <li> <a href="/article/2476815.html" target="_blank" title="有人写过用pear的mail的mail类发送带附件的邮件程序吗?可以给小弟我个例子吗"> <h2> 有人写过用pear的mail的mail类发送带附件的邮件程序吗?可以给小弟我个例子吗 </h2> </a> </li> <li> <a href="/article/2471640.html" target="_blank" title="CI框架简单邮件发送类实例"> <h2> CI框架简单邮件发送类实例 </h2> </a> </li> <li> <a href="/article/2465802.html" target="_blank" title="JAVA邮件发送的简单实现 博客分类: JAVA邮件发送的简单实现 备注  "> <h2> JAVA邮件发送的简单实现 博客分类: JAVA邮件发送的简单实现 备注   </h2> </a> </li> <li> <a href="/article/2465803.html" target="_blank" title="JAVA邮件发送的简单实现 博客分类: JAVA邮件发送的简单实现 备注  "> <h2> JAVA邮件发送的简单实现 博客分类: JAVA邮件发送的简单实现 备注   </h2> </a> </li> <li> <a href="/article/2457809.html" target="_blank" title="实现jsp验证码的简单小例子"> <h2> 实现jsp验证码的简单小例子 </h2> </a> </li> <li> <a href="/article/2457806.html" target="_blank" title="jspsmart文件上传与邮件发送的实例"> <h2> jspsmart文件上传与邮件发送的实例 </h2> </a> </li> <li> <a href="/article/2421729.html" target="_blank" title="JSP简单练习-使用JDOM创建xml文件"> <h2> JSP简单练习-使用JDOM创建xml文件 </h2> </a> </li> </ul> </div> </article> </div> </main> <footer><div class="box"><div class="ft_nav"><div class="ft_about"><p>关于网站</p><ul><li><a href="/sitemap.xml" target="_blank" title="网站地图">网站地图</a></li><li><a href="/list/2/" title="最新程序员文章站">最新程序员文章站</a></li></ul></div><div class="ft_contact"><ul><li>本站所有数据收集于网络如有侵犯到您的权益,请联系我们进行下架处理。</li><li class="email_show"></li></ul></div></div><div class="copyright"><div class="cr_left"><p> 备案号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤ICP备20058927号</a></p><p>© Copyright © 2020-2022 www.superweb999.com 程序员文章站. </p></div></div></div></footer> </body> </html>