public static String username="z63as"; sender's username public static String password="%"; sender's password public static String FromAddress = "[email protected]"; sending address (obtained from rs) public static String toAddress = "[email protected]"; sending address (obtained from rs) public static String subject = "Greetings"; email subject public static String content = "hello world" ; email content public static void main(String args[])throws Exception{ JavaMailSenderImpl mailSender=new JavaMailSenderImpl(); Properties properties=new Properties(); properties.setProperty("mail.smtp.auth","true"); properties.put("mail.smtp.host","smtp.126.com"); mailSender.setJavaMailProperties(properties); mailSender.setHost("smtp.126.com"); mailSender.setPort (25); mailSender.setUsername(username); mailSender.setPassword(password); MimeMessage mimeMessage=mailSender.createMimeMessage(); MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); messageHelper.setFrom(FromAddress, "XXX"); messageHelper.setSubject("Hello world"); messageHelper.setTo(toAddress); messageHelper.setText(content, true); html: true mailSender.send(mimeMessage); send mail }