public void SendMail(string senderName, string receivers, string subject, string body) { var message = new NewMailMessage(); message.SenderName = senderName; message.Time = DateTime.Now; message.DestinationList = receivers; message.Subject = subject; message.Body = body; message.Normalize(); ConnectionManager.Instance.Send("newMail"); ConnectionManager.Instance.Send(message.Serialize()); ConnectionManager.Instance.Close(); }
private void HandleNewMail(TcpClient client) { string username = _user; byte[] lengthByte = new byte[4]; _stream.Read(lengthByte, 0, 4); var length = BitConverter.ToInt32(lengthByte, 0); byte[] data = new byte[length]; _stream.Read(data, 0, length); var message = new NewMailMessage(); message.Deserialize(data); User requestingUser = _usersList.Find((user) => user.username == username); List<User> legitUsers = CheckRecieverUsersExsitanceAndFreeSpace(message.DestinationList, requestingUser); Mail newMailForUsers = new Mail(message.SenderName, message.Time.ToString(), legitUsers, message.Subject, message.Body); HandleSendingMail(newMailForUsers); }