title: Add attachment to mimekit mimemessage from memory stream in C#?
body: <p>I want to add xml attachment to mimekit message. I already have a memory stream and content type. How can I construct attachment and add it to mime message?</p>
  
  <pre><code>var message = new MimeMessage();
  message.From.Add(new MailboxAddress(myEmail));
  message.To.Add(new MailboxAddress(myEmail));
  message.Subject = "Test Email";
  message.Body = new TextPart("plain") { Text = @"This email is for testing purpose." };
  if (!string.IsNullOrEmpty(xml))
  {
      /* Attaching the xml without save it in disk */
      using (MemoryStream memoryStream = new MemoryStream())
      {
          byte[] contentAsBytes = Encoding.UTF8.GetBytes(xml);
          memoryStream.Write(contentAsBytes, 0, contentAsBytes.Length);
  
          // Set the position to the beginning of the stream.
          memoryStream.Seek(0, SeekOrigin.Begin);
  
          // Create attachment
          System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType
          {
              MediaType = MediaTypeNames.Application.Octet,
              Name = file
          };
  
          //here i would i like to add the memorystream and contenttype to mimemessage
          return;
      }
      using (var smptpClient = new MailKit.Net.Smtp.SmtpClient())
      {
          smptpClient.Connect(smtp, port, SecureSocketOptions.Auto);
          smptpClient.Authenticate(myEmail, myPass);
          smptpClient.Send(message);
          smptpClient.Disconnect(true);
      }
  }
  </code></pre>