邮箱中的文件下载后为什么会出现JSP格式?
可能是邮箱问题,这时候下载到的不是附件,应该是一个jsp页面. 可能是个bug,
应该会被马上修复的
如果老这样
可以问下你用的邮箱的管理员咨询下.
jsp中如何实现发送邮箱的功能?
这里面要加载javamail包 去网上找能找到的! activation.jar cos.jar mail.jar index.jsp %@ page contentType="text/html; charset=gb2312" language="java" errorPage="../error/error.jsp" % !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " " html head title发送电子邮件/title meta http-equiv="Content-Type" content="text/html; charset=gb2312" link rel="stylesheet" type="text/css" href="../image/com.css"//head body form method="post" name="form1" action="sendmail.jsp" onSubmit="return email()" table width="480" height="393" border="1" align="center" cellpadding="0" cellspacing="0" tr bordercolor="#D4D0C8" bgcolor="#FEFFC9" td height="27" colspan="2" align="left"div align="center"strong发送电子邮件/strong/div/td /tr tr bgcolor="#FEFFC9" td width="68" height="27" align="left"div align="right"收件人:/div/td td width="406" height="27"div align="center" input type="text" name="sname" size="51" /div/td /tr tr bgcolor="#FEFFC9" td height="27" align="left"div align="right"发件人:/div/td td height="27" div align="center" input type="text" name="jname" size="51" /div/td /tr tr bgcolor="#FEFFC9" td height="27" align="left"div align="right"密 码:/div/td td height="27"div align="center"input type="password" name="password" size="57"/div/td /tr tr bgcolor="#FEFFC9" td height="27" align="left"div align="right"主 题:/div/td td height="27"div align="center" input name="title" type="text" size="51" /div/td /tr tr align="left" bgcolor="#FEFFC9" td height="227" valign="top"div align="right"内 容:/div/td td height="227"div align="center" textarea name="message" cols="50" rows="15"/textarea /div/td /tr tr align="center" valign="middle" bordercolor="#D4D0C8" bgcolor="#FEFFC9" td height="29" colspan="2"input type="submit" name="Submit" value="发送" input type="reset" name="Submit2" value="清除"/td /tr /table /form /body /html sendmail.jsp(邮件发送!) %@ page contentType="text/html; charset=gb2312" language="java" errorPage="" % %@ page import="java.io.*" % %@ page import="java.util.*" % %@ page import ="javax.mail.*" % %@ page import="javax.mail.internet.*" % %@ page import="javax.activation.*" % !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " " html xmlns=" " head meta http-equiv="Content-Type" content="text/html; charset=gb2312" / title发送邮件/title /head link rel="stylesheet" type="text/css" href="../image/com.css"/ % try{ request.setCharacterEncoding("gb2312"); String from=request.getParameter("jname"); String to=request.getParameter("sname"); String subject=request.getParameter("title"); String messageText=request.getParameter("message"); String password=request.getParameter("password"); String S =request.getParameter("jname"); int n =S.indexOf('@'); int m=S.length() ; String server =S.substring(n+1,m); //建立邮件会话 Properties pro=new Properties(); pro.put("mail.smtp.host","smtp."+server); pro.put("mail.smtp.auth","true"); Session sess=Session.getInstance(pro); sess.setDebug(true); //新建一个消息对象 MimeMessage message=new MimeMessage(sess); //设置发件人 InternetAddress from_mail=new InternetAddress(from); message.setFrom(from_mail); //设置收件人 InternetAddress to_mail=new InternetAddress(to); message.setRecipient(Message.RecipientType.TO ,to_mail); //设置主题 message.setSubject(subject); //设置内容 message.setText(messageText); //设置发送时间 message.setSentDate(new Date()); //发送邮件 message.saveChanges(); //保存邮件信息 Transport transport =sess.getTransport("smtp"); // transport.connect("smtp."+server,from,password); //这一句很关键,相当于登陆管理员邮箱来发邮件 // transport.connect("smtp.163.com",wode@163.com,"123456"); transport.connect(" smtp.qq.com ",from,password); transport.sendMessage(message,message.getAllRecipients()); transport.close(); out.print("发送邮件成功"); }catch(Exception e){ out.print("发送邮件失败,原因可能是"); out.println(e.getMessage()); } % /html