用java发email

看了javamail的一些资料,挺麻烦的,还是commons的比较简单.贴上代码:(只是还没学会发附件,但现在发附件都要超大附件了,恐怕还是用客户端比较简单)

public static void main(String[] args) {
  SimpleEmail email = new SimpleEmail();
      email.setHostName("smtp.163.com");//设置使用发电子邮件的邮件服务器
      try {
        email.addTo("[email protected]");
        email.setAuthentication("[email protected]","password");
        email.setFrom("[email protected]");
        email.setSubject("Test apache.commons.mail message");
        email.setMsg("This is a simple test of commons-email");
        email.send();
      }
      catch (EmailException ex) {
        ex.printStackTrace();
      }
    }

你可能感兴趣的:(用java发email)