使用spring mail发送邮件
package com.my.test;import java.io.IOException;import java.util.Properties;import javax.mail.MessagingException;import javax.mail.internet.MimeMessage;import org.springframework.core.io.ClassPathResource;import org.springframework.mail.javamail.JavaMailSenderImpl;import org.springframework.mail.javamail.MimeMessageHelper;public class MailService {public void sendMail() throws MessagingException, IOException {final JavaMailSenderImpl mailSend = new JavaMailSenderImpl();mailSend.setDefaultEncoding("UTF-8");mailSend.setHost("smtp.163.com");mailSend.setUsername("***@163.com");mailSend.setPassword("***");Properties pro = new Properties();pro.put("mail.smtp.auth", "true");pro.put("mail.debug", "true");mailSend.setJavaMailProperties(pro);final MimeMessage mimeMessage = mailSend.createMimeMessage();MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");mimeMessageHelper.setFrom("***@163.com");mimeMessageHelper.setTo("***@qq.com");mimeMessageHelper.setSubject("测试发送邮件.");mimeMessageHelper.setText("<html><head></head><body><a href='http://www.baidu.com'>baidu</a></body></html>", true);ClassPathResource file1 = new ClassPathResource("333.jpg");mimeMessageHelper.addAttachment(file1.getFile().getName(), file1.getFile());mailSend.send(mimeMessage);}}