ublic class runmain
}// 附件傳送執行緒
class mail extends thread else else else
mail.send();
system.out.println(time + "附近已傳送完畢!");
if (this.getid() == thread.currentthread().getid()) catch (interruptedexception e) }}
}}}// 執行時間
private boolean dotime()
return result;
}// 設定郵件接收人
public void addreceivers(string recs, mail mail) }}
// 根據日期設定郵件傳送主題
public void setdatesubject(string subject, mail mail)
if (date.length() == 1)
mail.setsubject(year + month + date + subject);
}// 根據輪替規則確定接收人和傳送人
public void setsender(mail mail) ;
addreceivers(recs, mail);
mail.setfrom(sender);
}public void run()
// }
}private static final string line_end = "\r\n";
private boolean isdebug = false;
private boolean isallowreadsocketinfo = true;
private string host;
private string from;
private listto;
private listcc;
private listbcc;
private string subject;
private string user;
private string password;
private string contenttype;
private string boundary;
private string boundarynextpart;
private string contenttransferencoding;
private string charset;
private string contentdisposition;
private string content;
private string ******datepattern;
private string defaultattachmentcontenttype;
private listpartset;
private static mapcontenttypemap;
private class mailpart extends mail
}public mail()
private string getpartcontenttype(string filename)
ret = contenttypemap.get(filename);
}if (null == ret)
return ret;
}private string tobase64(string str, string charset) catch (unsupportedencodingexception e)
}return "";
}private string tobase64(byte bs)
private string tobase64(string str)
private string getallparts() }}
partset.clear();
return sbd.tostring();
}/**
* 新增郵件正文單元
*/private void addcontent()
}private string listtomailstring(listmailaddresslist) }}
return sbd.tostring();
}private listgetrecipient()
public void addattachment(string filepath)
public void addto(string mailaddress)
public void addcc(string mailaddress)
public void addbcc(string mailaddress)
public void addattachment(string filepath, string charset) catch (filenotfoundexception e) }}
public void addattachment(string filename, inputstream attachmentstream,
string charset)
}if (null != bs)
} catch (exception e) finally catch (ioexception e)
}runtime.getruntime().gc();
runtime.getruntime().runfinalization();}}
/*** 傳送郵件
* * @return 郵件伺服器反回的資訊
*/public string send()
// system.out.println(
// getallsendaddress());
pw.write("data" + line_end); // 開始輸入郵件
if (!readresponse(pw, br, infobuilder, "250"))
return infobuilder.tostring();
flush(pw);
// 設定郵件頭資訊
stringbuffer sbf = new stringbuffer("from: <" + from + ">"
+ line_end); // 發件人
******dateformat sdf = new ******dateformat(******datepattern);
// 新增郵件正文單元
addcontent();
// 合併所有單元,正文和附件。
// 傳送
pw.write(sbf.tostring());
readresponse(pw, br, infobuilder, "354");
flush(pw);
// quit退出
pw.write("quit" + line_end);
if (!readresponse(pw, br, infobuilder, "250"))
return infobuilder.tostring();
flush(pw);
return infobuilder.tostring();
} catch (exception e) finally catch (ioexception e)
// this.to.clear();
// this.cc.clear();
// this.bcc.clear();
this.partset.clear();}}
private void flush(printwriter pw)
}private boolean readresponse(printwriter pw, bufferedreader br,
stringbuilder infobuilder, string msgcode) throws ioexception
if (isdebug)
}return true;}}
定時傳送郵件
香港那邊的公司的erp糸統是bs模式,由於對方公司伺服器環境條件與解決方案要簡單的限制,我和我師傅決定用第三種方法。在程式設計之前,先介紹一下global.asax檔案裡的幾個方法。protected void protected void 下面是具體的做法 protected void new t...
delphi郵件定時傳送
unit smtp inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,stdctrls,idbasecomponent,idcomponent,idtcpconnection...
vbs定時傳送郵件
用vbs寫個指令碼,然後用windows平台下的計畫任務來呼叫,每天定時 郵件.dim connstr,conn dim sql,rs,msg sub opendb connstr dsn 51tiao.com uid sa pwd if not isobject conn then set con...