📄 sendmail_th.java
字号:
//package mailserver;
import java.sql.*;
import java.io.*;
import java.util.ArrayList;
public class SendMail_th implements Runnable
{
Mail_dbcon m_dbcon = null;
int jg_time = 30;//间歇时间
public SendMail_th(Mail_dbcon dbcon)
{
this.m_dbcon = dbcon;
String time_sfjgs = Ini.getValue("config", "re_jg_time");
if (!time_sfjgs.equals(""))
jg_time = Integer.parseInt(time_sfjgs);
new Thread(this).start();
}
public void run()
{
while (true)
{
String sqlstr = "select * from mail_list where m_mailstate='1'";
ResultSet rs = m_dbcon.f_getreset(sqlstr);
try
{
Thread.sleep(jg_time * 1000);
while (rs.next())
{
String mailid = rs.getString("m_mailid");
String mailbody = rs.getString("m_text");
//获取smtp服务器及油箱帐号、密码
String user = rs.getString("m_username");
sqlstr = "select u_mailname,u_mailword,u_smtp,u_effect from usermsg_list where u_username='" + user + "'";
ResultSet rrs = m_dbcon.f_getreset(sqlstr);
if (rrs == null)
continue;
String smtpstr = "";
String mailuser = "";
String mailword = "";
if (rrs.next())
{
String effect = rrs.getString("u_effect");
if (effect.equals("无效"))
continue;
smtpstr = rrs.getString("u_smtp");
mailuser = rrs.getString("u_mailname");
mailword = rrs.getString("u_mailword");
}
else
continue;
int mailport = 25;
if (smtpstr.equals("smtp.gmail.com"))
mailport = 465;
SendMail themail = new SendMail(smtpstr, mailport, mailuser, mailword);
if (themail.setSubject(rs.getString("m_title")) == false) continue;
if (themail.setBody(mailbody) == false) continue;
if (themail.setTo(rs.getString("m_reperson")) == false) continue;
if (themail.setFrom(rs.getString("m_sdperson")) == false) continue;
//是否有附件
sqlstr = "select mf_filename,mf_text from fmail_list where mf_mailid='"+mailid+"'";
ResultSet rss = m_dbcon.f_getreset(sqlstr);
ArrayList mf_list = new ArrayList();
if (rss != null)
{
while (rss.next())
{
String mf_filename = rss.getString("mf_filename");
String filepath = "linshi\\" + mf_filename;
File storefile = new File(filepath);
//Myprint("storefile's path: "+storefile.toString());
BufferedOutputStream bos = null;
try
{
byte mf_text[] = rss.getBytes("mf_text");
bos = new BufferedOutputStream(new FileOutputStream(storefile));
bos.write(mf_text);
bos.flush();
mf_list.add(storefile);
themail.addFileAffix(filepath);
}
catch (Exception excep)
{
excep.printStackTrace();
//throw new Exception("文件保存失败");
}
finally
{
bos.close();
//storefile.delete();
continue;
}
}
}
//if (themail.addFileAffix("c:\\boot.ini") == false) continue;
if (themail.sendout() == false)
{
MailSer_Form.Myprintlog(rs.getString("m_sdperson") + " 发送邮件失败!");
sqlstr = "update mail_list set m_mailstate='5' where m_mailid='"+mailid+"'";
m_dbcon.f_execute(sqlstr);
}
else
{
MailSer_Form.Myprintlog(rs.getString("m_sdperson") + " 发送邮件成功!");
sqlstr = "update mail_list set m_mailstate='2' where m_mailid='" + mailid + "'";
m_dbcon.f_execute(sqlstr);
}
for(int i=0;i<mf_list.size();i++)
{
((File)mf_list.get(i)).delete();
}
}
}
catch (Exception ex)
{
continue;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -