Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit c21fa1c

Browse files
committed
增加附件发送的测试
1 parent 22c4a79 commit c21fa1c

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/test/java/org/suren/autotest/web/framework/mail/MailTest.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@
1818

1919
package org.suren.autotest.web.framework.mail;
2020

21+
import org.junit.Ignore;
2122
import org.junit.Test;
2223
import org.junit.runner.RunWith;
2324
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.core.io.ByteArrayResource;
2526
import org.springframework.mail.MailSender;
2627
import org.springframework.mail.SimpleMailMessage;
28+
import org.springframework.mail.javamail.JavaMailSenderImpl;
29+
import org.springframework.mail.javamail.MimeMessageHelper;
2730
import org.springframework.test.context.ContextConfiguration;
2831
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2932
import org.suren.autotest.web.framework.AutoApplicationConfig;
3033
import org.suren.autotest.web.framework.AutoTestConfig;
31-
import org.suren.autotest.web.framework.util.EncryptorUtil;
34+
35+
import javax.mail.MessagingException;
36+
import javax.mail.internet.MimeMessage;
37+
3238

3339
/**
3440
* @author suren
@@ -41,7 +47,8 @@ public class MailTest
4147
private MailSender mailSender;
4248

4349
@Test
44-
public void mailSend()
50+
@Ignore
51+
public void simpleMail()
4552
{
4653
SimpleMailMessage msg = new SimpleMailMessage();
4754
msg.setFrom("[email protected]");
@@ -50,4 +57,20 @@ public void mailSend()
5057
msg.setSubject("subject");
5158
mailSender.send(msg);
5259
}
60+
61+
@Test
62+
@Ignore
63+
public void mimeMail() throws MessagingException
64+
{
65+
MimeMessage msg = ((JavaMailSenderImpl) mailSender).createMimeMessage();
66+
MimeMessageHelper mail = new MimeMessageHelper(msg, true);
67+
mail.addAttachment("attach_for_test",
68+
new ByteArrayResource("attach_for_test".getBytes()));
69+
mail.setFrom("[email protected]");
70+
mail.setTo("[email protected]");
71+
mail.setText("context");
72+
mail.setSubject("subject");
73+
74+
((JavaMailSenderImpl) mailSender).send(msg);
75+
}
5376
}

0 commit comments

Comments
 (0)