动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Jsp → 阅读文章

 JSP发送邮件实例

作者来源: 
阅读 数 211 人次 , 2006-3-29 4:23:00 


vishal_donth gave this response on 10/18/2000:
//these are the pakages to be 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 be 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 was 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 first. if u get any other server which
//supports relaying u can try this on that
//also.

//use this function in ur 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
session session = session.getdefaultinstance(props, null);
message 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 internet but not through a
//proxy......or else use a proxy which
//supports smtp

 本文Tags邮件  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:使用JSP+JAVABEAN+XML 开发的一个例子
· 下一篇:Windows下JSP开发环境的配置
· 利用JSP 2.0开发Web应用程序
· jsp的出错处理
· JSP的9种基本内置组件
· JSP中文问题解决方案
· jsp页面调用applet实现人民币的大小写转换 (二)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077