File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/test/java/com/example Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 8
8
import org .springframework .mail .javamail .JavaMailSenderImpl ;
9
9
import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
10
10
11
+ import javax .mail .*;
12
+ import javax .mail .internet .InternetAddress ;
13
+ import javax .mail .internet .MimeMessage ;
14
+ import java .util .Properties ;
15
+
11
16
/**
12
17
* Created by zhuzhengping on 2017/3/16.
13
18
* mail test
@@ -32,4 +37,27 @@ public void send(){
32
37
33
38
System .out .println ("mail has been send" );
34
39
}
40
+ @ Test
41
+ public void sendMail () throws MessagingException {
42
+ Properties properties = new Properties ();
43
+ Session session = Session .getInstance (properties , new Authenticator () {
44
+ @ Override
45
+ protected PasswordAuthentication getPasswordAuthentication () {
46
+ return new PasswordAuthentication ("zhu_zhengping@hotmail.com" ,"" );
47
+
48
+
49
+ }
50
+ });
51
+
52
+ Message message = new MimeMessage (session );
53
+ message .setFrom (new InternetAddress ("zhu_zhengping@hotmail.com" ));
54
+
55
+ message .setRecipient (Message .RecipientType .TO ,new InternetAddress ("407993723@qq.com" ));
56
+
57
+ message .setSubject ("123" );
58
+
59
+ message .setContent ("<h1>123:</h1><h3><a href='http://www.google.com'></h3>" ,"text/html;charset=utf-8" );
60
+
61
+ Transport .send (message );
62
+ }
35
63
}
You can’t perform that action at this time.
0 commit comments