邮件发送和接收已经全部实现,大家在转发市请注明出处(我这也是参考了N多大牛的作品):
//测试邮件发送类
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class SendTest {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void mailTest(){
SendMail mail=new SendMail();
MailInfo mailInfo=new MailInfo();
mailInfo.setContent("邮件内容44444444444444444444");
mailInfo.setFilepath("E:\\Emotion\\Photo\\乳沟.jpg");
String fname=mailInfo.getFilepath().substring(mailInfo.getFilepath().lastIndexOf("."), mailInfo.getFilepath().length());
System.out.println(fname);
// mailInfo.setFilename("希望"+fname);
mailInfo.setFromAddress("leeposter@163.com");
mailInfo.setHost("smtp.163.com");
mailInfo.setSubject("邮件主题444444444444444444444");
mailInfo.setToAddress("liposter@163.com");
mailInfo.setUsername("leeposter");
mailInfo.setValidate("true");
mailInfo.setPassword("*********");
try{
boolean flag=mail.Send(mailInfo);
if(flag==true){
System.out.println("发送成功");
}else{
System.out.println("发送失败");
}
}catch(Exception e){
e.printStackTrace();
}
}
}