eclipse
maven插件
注意,需要引入此包
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); senderImpl.setHost('smtp.163.com');// 设定smtp邮件服务器 SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom('xxx@163.com'); mailMessage.setSubject('标题'); mailMessage.setText('内容。。。'); senderImpl.setUsername(' xx用户名 '); // 根据自己的情况,设置username senderImpl.setPassword(' xx密码 '); // 根据自己的情况, 设置password Properties prop = new Properties(); prop.put(' mail.smtp.auth ', ' true '); // 将这个参数设为true,让服务器进行认证,认证用户名和密码是否正确 prop.put(' mail.smtp.timeout ', ' 25000 '); senderImpl.setJavaMailProperties(prop); // 发送邮件 mailMessage.setTo(' 发送给xx@xx.com '); senderImpl.send(mailMessage); System.out.println('send OK by lkmgydx');
直接做为main函数运行
注意maven需要引入以上两个依赖,不然会报错!