Attach A Meeting Schedule In ASP.Net With SMTP Mail With File Attachment

How to attach a meeting schedule of outlook in asp.net via SMTP Mail
 
C# Code
  1. public void SendMail(string tomailid,string resume)  
  2.         {  
  3.             try  
  4.             {  
  5.   
  6.                 string Body = "Your Mail Body ";  
  7.   
  8.                 //Attach Calender  
  9.                 string schLocation = "Conference Room";  
  10.                 string schSubject = "Your Subject";  
  11.                 string schDescription ="Description" ;  

  12.                 System.DateTime schBeginDate = Convert.ToDateTime(txtDate.Text +" "+ txtTime.Text);  
  13.                 System.DateTime schEndDate = schBeginDate.AddMinutes(30);  
  14.   
  15.                 //PUTTING THE MEETING DETAILS INTO AN ARRAY OF STRING  
  16.   
  17.                 String[] contents = { "BEGIN:VCALENDAR",  
  18.                               "PRODID:-//Flo Inc.//FloSoft//EN",  
  19.                               "BEGIN:VEVENT",  
  20.                               "DTSTART:" + schBeginDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),  
  21.                               "DTEND:" + schEndDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),  
  22.                               "LOCATION:" + schLocation,  
  23.                          "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + schDescription,  
  24.                               "SUMMARY:" + schSubject, "PRIORITY:3",  
  25.                          "END:VEVENT""END:VCALENDAR" };  
  26.   
  27.                 /*THE METHOD 'WriteAllLines' CREATES A FILE IN THE SPECIFIED PATH WITH  
  28.                THE SPECIFIED NAME,WRITES THE ARRAY OF CONTENTS INTO THE FILE AND CLOSES THE 
  29.                 FILE.SUPPOSE THE FILE ALREADY EXISTS IN THE SPECIFIED LOCATION,THE CONTENTS  
  30.                IN THE FILE ARE OVERWRITTEN*/  
  31.                 Random rnd = new Random();  
  32.                 string path = "~/MeetingFiles/" +rnd.Next().ToString()+".ics";  
  33.                 System.IO.File.WriteAllLines(Server.MapPath(path), contents);  
  34.   
  35.   
  36.   
  37.   
  38.   
  39.   
  40.                 //string name = Session["UserName"].ToString();  
  41.                 MailMessage mail = new MailMessage();  
  42.                 mail.To.Add(tomailid);  
  43.   
  44.                 mail.From = new MailAddress("Your Mail Id");  
  45.                 mail.Subject = "You have 1 scheduled Meeting";  
  46.                 mail.CC.Add("Mail CC if any");  
  47.                 mail.Attachments.Add(new Attachment(Server.MapPath(resume))); // attach the File
  48.                 Attachment mailAttachment = new Attachment(Server.MapPath(path));  
  49.                 mail.Attachments.Add(mailAttachment);  
  50.                  
  51.   
  52.                 mail.Body = Body;  
  53.   
  54.                 mail.IsBodyHtml = true;  
  55.                 SmtpClient smtp = new SmtpClient();  
  56.                 smtp.Port = 587;  
  57.   
  58.                 smtp.Host = "outlook.office365.com";  
  59.                 smtp.Credentials = new System.Net.NetworkCredential  
  60.                      ("Your Id""Your Password");  
  61.   
  62.                 smtp.EnableSsl = true;  
  63.                 smtp.Send(mail);  
  64.   
  65.             }  
  66.             catch (Exception ex)  
  67.             {  
  68.             }  
  69.         }