title: C# saving whole outlook .msg file in SQL Server database
body: <p>Is there anyway how to save whole <code>.msg</code> file with attachments from Outlook into a SQL Server database?</p>
  
  <p>I am able to send MailItem objects into database.</p>
  
  <pre><code>Outlook._Application _app = new Outlook.Application();
  Outlook.NameSpace _ns = _app.GetNamespace("MAPI");
  Outlook.MailItem item = _ns.GetItemFromID(selectedMailEntryId);
  
  string sentOn = item.SentOn.ToLongDateString() + " " + item.SentOn.ToLongTimeString();
  
  if (ServicesMail.InsertMail(txtSenderName.Text, txtSenderAddress.Text, item.Subject, txtQuestions.Text, txtAnswers.Text, item.HTMLBody, sentOn))
  {
      MessageBox.Show("Your Mail has been successfully saved in databse.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
  }
  </code></pre>
  
  <p>and this is the query.</p>
  
  <pre><code>cmd.CommandText = @"INSERT INTO EmailStorage (fullName, emailAddress, questions, answers, htmlBody, sentOn, savedOn, subject)
                      VALUES(@fullName, @emailAddress, @questions, @answers, @htmlBody, @sentOn, @savedOn, @subject)";
  
  cmd.Parameters.AddWithValue("@fullName", fullName);
  cmd.Parameters.AddWithValue("@emailAddress", emailAddress);
  cmd.Parameters.AddWithValue("@questions", questions);
  cmd.Parameters.AddWithValue("@answers", answers);
  cmd.Parameters.AddWithValue("@htmlBody", htmlBody);
  cmd.Parameters.AddWithValue("@sentOn", sentOn);
  cmd.Parameters.AddWithValue("@savedOn", DateTime.Now);
  cmd.Parameters.AddWithValue("@subject", subject);
  
  cmd.ExecuteNonQuery();
  </code></pre>
  
  <p>It works perfectly. But I need to store whole message, so I can take it from database when needed and open it in Outlook.</p>
  
  <p>Looked at many resources, but only found how to store it locally. Can anyone give me a hint?</p>