spring发送邮件
需要spring.jar mail.jar commons-logging-1.1.1.jar
发送代码 测试成功
JavaMailSenderImpl theMail = new JavaMailSenderImpl ();
//theMail.setProtocol("SMTP");theMail.setDefaultEncoding("UTF-8");
theMail.setHost("smtp.126.com");
theMail.setUsername("lixin1112003@126.com");
theMail.setPassword("XXXXXXX");
theMail.setPort(25);
Properties javaMailProperties=new Properties();
javaMailProperties.put("mail.smtp.auth", "true");
//javaMailProperties.put("mail.debug", "true");
javaMailProperties.put("mail.smtp.timeout", 0);
theMail.setJavaMailProperties(javaMailProperties);
MimeMessage mailMessage =
theMail.createMimeMessage();
MimeMessageHelper messageHelper =
new MimeMessageHelper(mailMessage, true);
messageHelper.setFrom(theMail.getUsername());
messageHelper.setTo("liaomin9992006@126.com");
messageHelper.setSubject("一个好东西");
messageHelper.setText("<a href=\"www.baidu.com\">进入百度</a>",true);
theMail.send(mailMessage);
System.out.println("郵件傳送成功...");