做一个BAT程序用JAVA,需要能实现发送邮件的功能。
大家谁有相应的代码提供下,APATCH下有什么包支持发送邮件的吗

解决方案 »

  1.   

    这个java ee5  就支持
      

  2.   

    mail-1.4.jar,jaxen-1[1].1-beta-6.jar,配上这两个包
      

  3.   

    http://user.qzone.qq.com/19810109/blog/1286955258
    我的QQ主页 已测试过
    不带附件的 带附件 HTML格式的都有  
      

  4.   

    activation.jar包和mail.jar包 哪里有下载的地方
    谢谢
      

  5.   

    本人写过的
    import java.util.Date;
    import java.util.Properties;
     
    import javax.mail.Authenticator;
    import javax.mail.Message;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
     
    public class MailSender {
       
        private String  smtp = "smtp.qq.com";  // 邮件服务器
       
        private String username = "11111";
        private String password = "xxxxx";
       
        private String from = username+"@qq.com";
       
        EmailAuthenticator auth = new EmailAuthenticator(this.username,this.password);
       
        Properties props = System.getProperties();
        {
           props.put("mail.smtp.host",smtp);
           props.put("mail.smtp.auth", "true");
        }
       
        Session session = Session.getDefaultInstance(props,(Authenticator)auth);
        Message msg = new MimeMessage(session);
       
        public void sendTo(String to){
           try{
               msg.setFrom(new InternetAddress(from));
               msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
               msg.setSubject("用户注册验证");
               msg.setSentDate(new Date());
              
               msg.setText("xxxxx");
              
               Transport transport = session.getTransport("smtp");
               transport.connect(smtp, from, password);
               transport.sendMessage(msg,msg.getAllRecipients());
               transport.close();
               System.out.println("OK");
           }catch(Exception e){
              
           }
        }
       
        public static void main(String[] args) {
           new MailSender().sendTo("[email protected]");
          
        }
       
    }
    class EmailAuthenticator extends Authenticator{
        private String username, password;
        public EmailAuthenticator(String username, String password){
           this.username = username;
           this.password = password;
        }
        public PasswordAuthentication getPasswordAuthentication(){
           return new PasswordAuthentication(this.username, this.password);
        }
    }另外 java 需要的jar  在 java ee 5 中已经带了 , 不需要额外下载吧
      

  6.   

    可以的。邮件发送可以用javaMail。非常好用,只要有个邮件服务器就可以了
      

  7.   

    用我这个吧。 写一个工具类。比较清楚简单package org.wg.test;import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;public class MailExample {
    public static void main(String args[]) throws Exception, MessagingException {
      String host = "smtp.163.com";//发送邮件服务器
      String from = "发送者的邮箱地址";
      String to = "接受者的邮箱地址";  // new properties
      Properties props = new Properties();  // Setup mail server
      props.put("mail.smtp.host", host);// 设置smtp主机  props.put("mail.smtp.auth", "true");// 使用smtp身份验证  // Get session
      Session session = Session.getDefaultInstance(props, null);  // Define message
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(from));
      message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
      message.setSubject("test");//标题
      message.setText("http://www.baidu.com/"+"This is test JavaMail");//内容   
      //http协议部分会自动转换成超链接
      message.saveChanges();  // Send message
      Transport transport = session.getTransport("smtp");
      System.out.println("正在连接");
      transport.connect(host, "发送者邮箱地址/用户名", "发送者密码");
      System.out.println("正在发送");
      transport.sendMessage(message, message.getAllRecipients());
      System.out.println("邮件发送成功");
    }
    }
      

  8.   

    感觉和我的差不多……看来.net和java的差别也不大哦