spring emil简单应用及常见问题

简单示例: 这里只是为了说明使用。实际应用中设置在bean中即可
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();			
			javaMailSender.setHost("smtp.126.com");   //设置邮箱服务器
			javaMailSender.setUsername("username");  //设置用户名(要与发送人相一致)
			javaMailSender.setPassword("password");   //密码
			
			
			SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
			simpleMailMessage.setSubject("this test");		
			simpleMailMessage.setTo("[email protected]");
			simpleMailMessage.setFrom("[email protected]"); //与上面要一致,不然也会出错
			simpleMailMessage.setText("this is test!!!!!!!!");
			
			Properties props = new Properties();  //此处必须设置,
			props.put("mail.smtp.auth", "true");  //不设置会出现 553错误,见错误1
			javaMailSender.setJavaMailProperties(props);  
			javaMailSender.send(simpleMailMessage);  //发送


错误1:
com.sun.mail.smtp.SMTPSendFailedException: 553 authentication is required,smtp4,jdKowLC7owA_aM1M2eDNAA--.4000S2 1288529984


错误2:如果出现此错误,少个mail.jar文件,把下面文件加上即可
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
	at TestMial.main(TestMial.java:21)

你可能感兴趣的:(java,spring,应用服务器,bean,sun)