哪位有邮件自动回复系统的源码
能共享下吗?
谢谢了

解决方案 »

  1.   

    先建两个类,AuthenticatorUtil.java和EMail.java;
    调用方法:new Email().sendMail(接收邮箱地址,邮件主题,邮件体内容)
    AuthenticatorUtil.java清单:
    package p1;
    import javax.mail.PasswordAuthentication;
    //当smtp需要验证时所需要用到的验证类
    class AuthenticatorUtil
        extends javax.mail.Authenticator {
      private String strUser;
      private String strPwd;  public AuthenticatorUtil(String user, String password) {
        this.strUser = user;
        this.strPwd = password;
      }EMail.java清单:
    package p1;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import p1.AuthenticatorUtil;public class EMail{  public EMail() {}  //此方法执行邮件发送的操作
      //mailTo:目标邮件地址
      //mailSubject:邮件主题
      //mailBody:邮件体,在这里是邮件正文
      public boolean sendMail(String mailTo,String mailSubject,String mailBody){
          try {
            //初始化所有必要的参数
            String smtpServer = "smtp.bbbb.com";//smtp服务器
            String smtpAuth = "true";//smtp服务器是否需要进行验证
            String smtpUser = "uuuuu";//smtp分配的用户名(就是你的E-Mail地址中@符号前面部分)
            String smtpPassword = "pppp";//登陆口令
            String from = "[email protected]";//用于在对方收到的邮件中作为发送人地址显示
            String to = mailTo;//邮件需要发送到的目标邮件地址
            String subject = mailSubject;//邮件主题
            String text = mailBody;//邮件体,在这里是邮件正文
            Properties props = new Properties();//构造Properties,作为后面的Session参数容器
            Session sendMailSession;
            Transport transport;
            props.put("mail.smtp.host", smtpServer);
            props.put("mail.smtp.auth", smtpAuth);
            if ("true".equals(smtpAuth)) {
              //如果smtp服务器需要验证,则构建AuthertiactorUtil用于mail session的创建
              AuthenticatorUtil authutil = new AuthenticatorUtil(smtpUser, smtpPassword);
              sendMailSession = Session.getInstance(props, authutil);
            }
            else {
              sendMailSession = Session.getInstance(props);
            }        //设置是否是调试状态,如果这里设置为true的话,则会在控制台输出发送过程,输出信息类似于在telnet上发送邮件
            sendMailSession.setDebug(true);
            //初始化邮件消息
            Message message = new MimeMessage(sendMailSession);
            message.setFrom(new InternetAddress(from));
            message.setRecipient(Message.RecipientType.TO,
                                    new InternetAddress(mailTo));
            message.setSubject(subject);
            message.setSentDate(new Date());
            message.setText(text);
            message.saveChanges();
            transport = sendMailSession.getTransport("smtp");//此次会话是发送邮件(smtp)
            transport.send(message, message.getAllRecipients());//从这里可以看出来,可以设置多个发送目的地址
            transport.close();
          }catch (Exception e) {
            System.err.println("邮件发送失败:" + e.getMessage());
            return false;
          }
          return true;
        }
    }  protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(strUser, strPwd);
      }
    }
      

  2.   

    借用搂主宝地用一下
    我怎么没有javax.mail.*包阿?