1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class) @SpringBootTest public class BlogApplicationTests { @Resource private JavaMailSender javaMailSender;
@Value("${spring.mail.username}") private String sender;
@Test public void contextLoads() { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(sender); message.setTo("[email protected]"); message.setSubject("测试邮件(邮件主题)"); message.setText("这是邮件内容"); javaMailSender.send(message); }
}
|