提示发送错误!如果不带附件可以正常发送
<%@ page contentType="text/html; charset=GB2312" %>
<%@page import="java.util.*"%>
<%@page import="java.io.File"%>
<%@page import="javax.mail.*"%>
<%@page import="javax.mail.internet.*"%>
<%@page import="javax.activation.*"%> 
<%@page import="com.jspsmart.upload.*"%> 
<jsp:useBean id="myUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<html>
<head>
<title>sendmail.jsp</title>
</head>
<body>
<%
Properties props=new Properties();
//设置邮件服务
props.put("127.0.0.1","smtp.zgy.com");
Session session2 = Session.getDefaultInstance(props,null);try{
//设置邮件头信息代码如下:Message msg = new MimeMessage(session2);
msg.setFrom(new InternetAddress("[email protected]"));
InternetAddress[] addressTo = {new InternetAddress("[email protected]")};
msg.setRecipients(Message.RecipientType.TO,addressTo);
//create the message part
MimeBodyPart mbp1 = new MimeBodyPart();
//设置邮件内容,构建程序段如下
mbp1.setText("内容");
Multipart mp = new MimeMultipart(); 
mp.addBodyPart(mbp1);//附件myUpload.initialize(pageContext); 
myUpload.upload(); 
for (int i=0;i<myUpload.getFiles().getCount();i++)
{
 com.jspsmart.upload.File myFile = myUpload.getFiles().getFile(i);
 if (!myFile.isMissing()) {
  myFile.saveAs("/upload/" + myFile.getFileName()); 
  out.print(myFile.getFileName());
  i ++;
 }
}
  //for(int i=0;request.getParameter("File"+i)!=null;i++)
//{
 mbp1 = new MimeBodyPart();
 File file=new File("/upload/","22.htm");//我上传的就是22.htm
 DataSource source =new FileDataSource(file);
 mbp1.setDataHandler(new DataHandler(source));
 mbp1.setFileName("22.htm");
 mp.addBodyPart(mbp1);
//}msg.setContent(mp);
 
msg.setSubject("标题");
msg.setSentDate(new Date());
Transport.send(msg);
}
catch(Exception ex){
 out.println("发送失败");
}%>
</body>
</html>