title: Sending Mails with attachment in C#
body: <p>I need to send a mail  including the exception details (Yellow Screen Of Death) as attachment.</p>
  
  <p>I could get the YSOD as follows:</p>
  
  <pre><code>string YSODmarkup = lastErrorWrapper.GetHtmlErrorMessage();
  if (!string.IsNullOrEmpty(YSODmarkup))
  {
      Attachment YSOD = Attachment.CreateAttachmentFromString(YSODmarkup, "YSOD.htm");
      mm.Attachments.Add(YSOD);
  }
  </code></pre>
  
  <p><code>mm</code> is of type <code>MailMessage</code>, but the mail is not sent.</p>
  
  <p>Here</p>
  
  <pre><code>System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("from", "to", "Exception-Details", htmlEmail.ToString());
  </code></pre>
  
  <p>is used  to  bind the body of the mail.</p>
  
  <p>After this only the attachment is added.
  While removing the attachment, mail is sent.</p>
  
  <p>Can anyone help me out?</p>
  
  <hr>
  
  <p>As per the comments from Mr. Albin  and Mr. Paul am updating the following</p>
  
  <pre><code>        string YSODmarkup = Ex_Details.GetHtmlErrorMessage();
          string p = System.IO.Directory.GetCurrentDirectory();
          p = p + "\\trial.txt";
          StreamWriter sw = new StreamWriter(p);
          sw.WriteLine(YSODmarkup);
          sw.Close();
          Attachment a = new Attachment(p);       
  
          if (!string.IsNullOrEmpty(YSODmarkup))
          {
               Attachment  YSOD = Attachment.CreateAttachmentFromString(YSODmarkup, "YSOD.html");
              System.Net.Mail.Attachment(server.mappath("C:\\Documents and Settings\\user\\Desktop\\xml.docx"));
  
               MyMailMessage.Attachments.Add(a);
  
          }  
  </code></pre>
  
  <p>Here i attached the contents to a text file and tried the same. So the mail was not sent. Is there any issue with sending mails which contains HTML tags in it. Because i was able to attach a normal text file. </p>