您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 简易实用的JavaMail邮箱程序
  所属分类: Java
  开发工具:
  文件大小: 481kb
  下载次数: 0
  上传时间: 2010-08-19
  提 供 者: hexia*****
 详细说明: package com.hx.mail; import java.util.HashMap; import java.util.Map; import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.Session; import javax.mail.PasswordAuthentication; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; /** * MailServices 邮件接收发送接口实现类 * * @author 380595305@qq.com * Date 2010-05-11 * @version 1.0 */ public class KumMailServicesImpl implements KumMailServices { /** MailboxType 邮箱类型 */ private static Map MailboxTypes = null; /** host 邮箱服务器类型 */ private String host = null; /** sender 邮件发送者 */ private String sender = null; /** addressee 邮件接收者 */ private String addressee = null; /** subject 邮件主题 */ private String subject = null; /** text 邮件消息 */ private String text = null; public static void init(){ MailboxTypes = new HashMap(); MailboxTypes.put("163","smtp.163.com"); MailboxTypes.put("139","smtp.139.com"); MailboxTypes.put("126","smtp.126.com"); MailboxTypes.put("qq", "smtp.qq.com"); MailboxTypes.put("live","smtp.live.cn"); MailboxTypes.put("msn","smtp.msn.com"); MailboxTypes.put("kum", "mail.kum.net.cn"); MailboxTypes.put("hotmail","smtp.hotmail.cn"); } /** * initialization 实例化类成员变量 */ private void initialization(String sender,String addressee,String subject,String text){ this.sender = sender; this.addressee = addressee; this.subject = subject; this.text = text; this.host = getHost(sender); //System.out.println("sender->"+this.sender+" | addressee->"+this.addressee+" | subject->"+this.subject+" | text->"+this.text+" | host->"+this.host); } /** * getHost 获取目标邮箱服务器类型 * * @param sender 是String类型,传入邮件发送者邮箱地址信息 * @return String 返回目标邮箱服务器类型 */ private String getHost(String sender){ String _host,_host_ = null; _host = sender.substring(sender.indexOf("@")+1,sender.indexOf(".")); if(MailboxTypes==null){ init(); } _host_ = MailboxTypes.get(_host); // System.out.println(_host+" <--> "+_host_); if(_host_==null){ //MailboxTypes.put(_host,"smtp."+_host+".com"); MailboxTypes.put(_host,"smtp."+sender.substring(sender.indexOf("@")+1,sender.length())); } return MailboxTypes.get(_host); } public void sendMail(String sender, String password, String addressee, String subject, String text) throws Exception { initialization(sender,addressee,subject,text); Properties props = System.getProperties(); { props.put("mail.smtp.host",this.host); props.put("mail.smtp.auth","true"); } ValidateAuther auther = new ValidateAuther(this.sender,password); Session session = Session.getDefaultInstance(props,auther); MimeMessage msg = new MimeMessage(session); InternetAddress fromAddr = new InternetAddress(this.sender); // 发送者邮箱地址 InternetAddress toAddr = new InternetAddress(this.addressee); // 接收者邮箱地址 msg.setFrom(fromAddr); msg.addRecipient(Message.RecipientType.TO, toAddr); /** * Message.RecipientType.TO -- 接收者 * Message.RecipientType.CC -- 抄送 * Message.RecipientType.BCC --秘密抄送者 */ msg.setSubject(this.subject); // 邮件主题 msg.setText(this.text); // 邮件信息 Transport.send(msg); // 发送邮件 } } /** * ValidateAuther 邮件验证类,验证邮件发送者信息 */ class ValidateAuther extends Authenticator { /** 邮件发送者 */ private String sender; /** 邮件接受者 */ private String password; /** * ValidateAuther 验证邮件发送者信息 * * @param userName 是String类型,传入邮件发送者账户 * @param password 是String类型,传入邮件发送者账户密码 */ public ValidateAuther(String sender, String password) { this.sender = sender; this.password = password; } /** * getPasswordAuthentication 验证邮件发送者账户信息的函数 * * @param userName 邮件发送者账户信息 * @param password 邮件发送者账户密码 * @return PasswordAuthentication 返回邮件发送者账户验证信息 */ @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(sender, password); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 输入关键字,在本站1000多万海量源码库中尽情搜索: