📄 sendmailall.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="javax.mail.*,javax.mail.internet.*,javax.activation.*,java.io.*,java.text.*,java.util.*"%>
<jsp:useBean id="emailsend" scope="page" class="myemail.MailSend" />
<jsp:useBean id="FileIo" scope="page" class="myemail.FileWrite" />
<%!
public String getStr(String str)
{
try
{
String temp1=str;
byte[] temp2=temp1.getBytes("ISO8859-1");
String temp=new String(temp2);
return temp;
}
catch(Exception e)
{
}
return "null";
}
//打开要传送的文件写入字符串中返回
public int OpenText(String FilePath)
{
try
{
//算出当前时间
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date dateTime= new Date();
String sDateTime=dateFormat.format(dateTime);
sDateTime=sDateTime.substring(0,10);
//生成文件对象
File oFile=new File(FilePath);
RandomAccessFile rafFile=new RandomAccessFile(oFile,"r");
String qishu=rafFile.readLine();
int iqishu=0;
if (!qishu.equals(sDateTime))
{
qishu=rafFile.readLine();
//进行期数运算
iqishu=java.lang.Integer.parseInt(qishu);
iqishu=iqishu+1;
qishu=java.lang.Integer.toString(iqishu);
}
else
{
qishu=rafFile.readLine();
//进行期数运算
iqishu=java.lang.Integer.parseInt(qishu);
}
rafFile.close();
//开始写期数到文件
BufferedWriter out2=new BufferedWriter(new FileWriter(oFile.getPath(),false));
String newline = System.getProperty("line.separator");
out2.write(sDateTime+newline);
out2.write(qishu+newline);
out2.close();
return iqishu;
}
catch(IOException ww)
{
System.out.println (ww);
return 0;
}
}
//将要发送的正文写入日志目录
public void WriteFile(String logfilepath,String WriteFileText)
{
try
{
File wFile=new File(logfilepath);
BufferedWriter outFile=new BufferedWriter(new FileWriter(wFile.getPath(),false));
outFile.write(WriteFileText);
outFile.close();
}
catch(IOException ww)
{
System.out.println (ww);
}
}
%>
<%
String logPath=request.getRealPath("/emailsend/log");//正式发送必须有效
//String logPath=request.getRealPath("/sendemail/log");
emailsend.MailList();
//FromList函数参数有日志路径logPath、主题"test"、正文stest、正文格式"html"
//String stest=new String(sTest1.getBytes("ISO8859_1"));//无需转换内码
String filePath=request.getRealPath("/emailsend/email_html/policy.htm"); //正式发送必须有效
String stest=FileIo.ReadFile(filePath);//正式发送必须有效
//String stest="测试使用";
WriteFile(logPath+"/sendtext.txt",stest);
//"test"为主题,stest为正文
//期数的文件路径
String qishupath=request.getRealPath("/emailsend/date.txt"); //正式发送必须有效
int iqi=OpenText(qishupath);
if (iqi>0)
{
String javabian=java.net.URLEncoder.encode("法律之星--每日政策立法动态("+iqi+")");
emailsend.FromList(logPath,javabian,stest,"html");
}
//out.println("当前期数为"+iqi);
response.sendRedirect("email.jsp?jspClass=send");
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -