public static void StoreToRecycleBin(string folderOwner, string folder, string messageFile) { string text = Guid.NewGuid().ToString().Replace("-", ""); string text2 = ""; int num = 0; try { Mail_Message entity = Mail_Message.ParseFromFile(messageFile); text2 = IMAP_Envelope.ConstructEnvelope(entity); num = (int)new FileInfo(messageFile).Length; } catch { } if (!Directory.Exists(RecycleBinManager.m_RecycleBinPath)) { try { Directory.CreateDirectory(RecycleBinManager.m_RecycleBinPath); } catch { } } File.Copy(messageFile, RecycleBinManager.m_RecycleBinPath + text + ".eml"); using (FileStream file = RecycleBinManager.GetFile()) { file.Position = file.Length; byte[] bytes = Encoding.UTF8.GetBytes(string.Concat(new object[] { text, " ", DateTime.Now.ToString("yyyyMMddHHmmss"), " ", folderOwner, " ", TextUtils.QuoteString(folder), " ", num, " ", TextUtils.QuoteString(text2), "\r\n" })); file.Write(bytes, 0, bytes.Length); } }
/// <summary> /// Stores specified message to recycle bin. /// </summary> /// <param name="folderOwner">Folder woner user.</param> /// <param name="folder">Folder what message it is.</param> /// <param name="messageFile">Message file name with path.</param> public static void StoreToRecycleBin(string folderOwner, string folder, string messageFile) { string messageID = Guid.NewGuid().ToString().Replace("-", ""); string envelope = ""; int size = 0; try{ // Parse message Mail_Message m = Mail_Message.ParseFromFile(messageFile); // Construct envelope envelope = IMAP_Envelope.ConstructEnvelope(m); size = (int)new FileInfo(messageFile).Length; } catch { } if (!Directory.Exists(m_RecycleBinPath)) { try{ Directory.CreateDirectory(m_RecycleBinPath); } catch { } } // Store recycle bin copy of message File.Copy(messageFile, m_RecycleBinPath + messageID + ".eml"); // Update index file using (FileStream fs = GetFile()){ fs.Position = fs.Length; // MessageID DeleteDate UserName Folder InternalDate Flags Subject byte[] record = System.Text.Encoding.ASCII.GetBytes( messageID + " " + DateTime.Now.ToString("yyyyMMddHHmmss") + " " + folderOwner + " " + TextUtils.QuoteString(folder) + " " + size + " " + TextUtils.QuoteString(envelope) + "\r\n" ); fs.Write(record, 0, record.Length); } }
/// <summary> /// 發送eml文件 /// </summary> /// <param name="authhh"></param> /// <param name="toMail"></param> /// <param name="pathMel"></param> public static void SendMailToMel(AUTH_SASL_Client_Plain authhh, string toMail, string pathMel, string smtp, int port, bool ssl) { try { using (LumiSoft.Net.SMTP.Client.SMTP_Client client = new LumiSoft.Net.SMTP.Client.SMTP_Client()) { client.Connect(smtp, port, ssl); client.EhloHelo(smtp); client.Auth(authhh); client.RcptTo(toMail); var msg = Mail_Message.ParseFromFile(pathMel); MemoryStream stream = new MemoryStream(); msg.ToStream(stream, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8); stream.Position = 0; client.SendMessage(stream); client.Disconnect(); } } catch (Exception ex) { throw ex; } }