title: Attaching a file to an email C#
body: <p>I've tried many of the solutions provided on this site to attach a file to an email, but no matter what I try I always get the "Sorry, something went wrong. You may want to try again" message at the line where I try to attach the file to my outlook mailitem.</p>
  
  <pre><code>  try
          {
              App = new Microsoft.Office.Interop.Outlook.Application();
  
              MailItem mailItem = App.CreateItem(OlItemType.olMailItem);
  
              mailItem.Subject = Subject;
              mailItem.To = To;
              mailItem.CC = CC;
              mailItem.BCC = BCC;
              mailItem.Body = Body;
  
              // make sure a filename was passed
              if (string.IsNullOrEmpty(FileAtachment) == false)
              {
                  // need to check to see if file exists before we attach !
                  if (!File.Exists(FileAtachment))
                      MessageBox.Show("Attached document " + FileAtachment + " does not exist", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  else
                  {
                      System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(FileAtachment);
                      mailItem.Attachments.Add(attachment, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                  }
              }
              mailItem.Display();     // display the email
          }
          catch (System.Exception ex)
          {
              MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
          }
  </code></pre>
  
  <p>Can anyone offer any idea how to get this to work ? I can send emails without any problem, but when I try to add an attachment it doesn't work :(</p>