#Region receives external mail
public void ReceiveMails (string Username, int OrderID) {jmail.Message Msg = new jmail.Message (); jmail.POP3 jpop = new jmail.POP3 (); if (! OrderID = 0) {SqlDataReader dataReader = this.ExtGetSetting ( UserName, ORDERID; if (DataReader.Read ()) {IF (DataReader ["Popserver"]. TOSTRING ()! = "&& DataReader [" PopuserName "]. TOSTRING ()! =") {Jpop.connect DataReader ["PopuserName"]. TOSTRING (), DataReader ["Poppassword"]. TOSTRING (), DataReader ["Popserver"]. Tostring (), int32.parse (DataReader ["Popport"]. Tostring ()); For (int i = 1; i <= jpop.count; i ) {msg = jpop.Messages [i]; this.saveextmail (MSG, Username, DataReader ["email"]. Tostring (), jpop.getMessageUid (i ));} Jpop.disconnect ();}}}}
#endregion} #Region Get settings ///
/// Get the contents of the settings ///
Public SqlDataReader ExtgetSetting (String UserName, Int ORDERID)
{
// Create Data Object and params
SqlDataReader DataReader = NULL;
Database data = new database ();
Sqlparameter [] PRAMS = {
Data.makeinparam ("@ username", sqldbtype.nvarchar, 20, username,
Data.makeinparam ("@ OrderID", SqldbType.Int, 1, OrderID
}
Try
{
// Run the stored processure
Data.Runproc ("sp_mailext set", PRAMS, OUT DATAREADER;
Return DataReader;
}
Catch (Exception EX)
{
Error.log (EX.TOString ());
Throw new Exception ("Get the content of the settings!", ex);
}
}
#ndregion
Store procedure:
Create Procedure SP_MAILEXTGETSET (@username [nvarchar] (50), @orderid [int]) as select * from TabextMailSetting where username = @ username and orderid = @ OrderIDGosub sendmail () TRY
DIM MS AS NEW JMAIL.MESSAGECLASS MS.SUBJECT = "I Want A Test" ms.body = "this is mybody" ms.silent = true ms.charset = "gb2312" ms.from = "zzq9624@163.com" MS .Fromname = "zzq" ms.addrecipient ("zhanqiangz @ yahoo.com, cn", "zzq", "zhanqiangz @ yahoo.com, cn") MS.AddRecipient ("zzq9624@163.com") 'ms.encoding = "Base64" ms.mailserverusername = "zzq9624" ms.mailserverpassword = "ssss"
Ms.Priority = 3 ms.send ("smtp.163.com", false 'ms.addattachment (txtpath.postedfile.filename, true, "text / html") ms = Nothing response.write ("ok") Catch Exception Response.write ("No" & ex.Message & Ex. Source)
End try # region external mail body Save ///
/// External mail body saves ///
///
Mail class
Public void saveextmail (Jmail.Message JMSG, String Username, String Email, String MessageID)
{
// create data object and paramsDatabase data = new Database (); SqlParameter [] prams = {data.MakeInParam ( "@ MailID", SqlDbType.NVarChar, 100, MessageID), data.MakeInParam ( "@ Username", SqlDbType.NVarChar , 300, Username, Data.makeinparam ("@ email", Sqldbtype.nvarchar, 100, email), Data.makeinParam ("@ readflag", sqldbtype.bit, 1, 0), DATA.MAKEINPARAM ("@ folderid" , SQLDBTYPE.INT, 20, 1), DATA.MAKEINPARAM ("@Headerstext", Sqldbtype.Nvarchar, 1000, JMsg.Headers .tostring ()), DATA.MAKEINPARAM ("@ Subject", SqldbType.nvarchar, 100, JMSG .Subject.toString ()), DATA.MAKEINPARAM ("@ textcontent", sqldbtype.nvarchar, 3000, jmsg.text.tostring ()), DATA.MAKEINPARAM ("@ htmlcontent", sqldbtype.nvarchar, 3000, "") Data.makeinparam ("@ fromname", sqldbtype.nvarchar, 300, ""), data.makeinparam ("@Fromemail", SqldbType.nvarchar, 200, ""), DATA.MAKEINPARAM ("@ ccto", sqldbtype. NVARCHAR, 200, "" ", Data.makeinparam (" @ bccto ", sqldbtype.nvarchar, 200," "), data.makeinparam (" @ replyto ", sqldbtype.nvarchar, 200," " ), Data.makeinparam ("@ senddate", sqldbtype.datetime, 30, datetime.pars (jmsg.date.tostring ()))), Data.MakeinParam ("@ bodysize", sqldbtype.nvarchar, 20, ""), Data.makeinparam ("@ size", sqldbtype.int, 5, 12)}; try {data.runproc ("sp_mailextmailadd", prams); data = null;} catch (exception ex) {error.log (ex.totring ()); Throw new Exception ("External mail is saved!", ex);