title: C# create outlook message with created PDF file attached
body: <p>I would like to know, how I could attach my created PDF file with Windows Form Data into a new outlook email message. With the following code I create the PDF. I could write it in the same else brackets:</p>
  
  <pre><code>else {
  CreatePDF();
  //This is an example EmailMessage();
  }
  
  private void EmailMessage()
      {
          try
          {                
              Outlook.MailItem mailItem = (Outlook.MailItem)
                  this.CreateItem(Outlook.OlItemType.olMailItem);
              mailItem.Subject = "This is the subject";
              mailItem.To = "someone@example.com";
              mailItem.Body = "This is the message.";
              mailItem.Importance = Outlook.OlImportance.olImportanceLow;
              mailItem.Display(false);
          }
          catch (Exception eX)
          {
              throw new Exception("cDocument: Error occurred trying to Create an Outlook Email"
                                  + Environment.NewLine + eX.Message);
          }
      }
  
  public void CreatePdf()
  {
  
      try
      {
          string imageFile = "";
          System.Drawing.Rectangle bounds = this.Bounds;
          using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
          {
              using (Graphics g = Graphics.FromImage(bitmap))
              {
                  g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
                  //pictureBox1.Image();
              }
              //==================add firstname 
              if (textBox1.Text != null &amp;&amp; textBox1.Text.Trim() != "")
              { imageFile = "C:/Users/Marc/Desktop/" + DateTime.Now.ToString("dddd dd MMMM hh-mm-ss tt") + textBox1.Text; }
              else
              { imageFile = "C:/Users/Marc/Desktop/" + DateTime.Now.ToString("dddd dd MMMM hh-mm-ss tt") + "Rectangle"; }
  
  
              bitmap.Save(imageFile + ".bmp", ImageFormat.Bmp);
              formToImage(imageFile);
          }
      }
      catch (Exception e)
      {
          MessageBox.Show(e.Message.ToString());
      }
  }`
  </code></pre>