How to attach a meeting schedule of outlook in asp.net via SMTP Mail
C# Code
- public void SendMail(string tomailid,string resume)
- {
- try
- {
-
- string Body = "Your Mail Body ";
-
-
- string schLocation = "Conference Room";
- string schSubject = "Your Subject";
- string schDescription ="Description" ;
- System.DateTime schBeginDate = Convert.ToDateTime(txtDate.Text +" "+ txtTime.Text);
- System.DateTime schEndDate = schBeginDate.AddMinutes(30);
-
-
-
- String[] contents = { "BEGIN:VCALENDAR",
- "PRODID:-//Flo Inc.//FloSoft//EN",
- "BEGIN:VEVENT",
- "DTSTART:" + schBeginDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),
- "DTEND:" + schEndDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),
- "LOCATION:" + schLocation,
- "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + schDescription,
- "SUMMARY:" + schSubject, "PRIORITY:3",
- "END:VEVENT", "END:VCALENDAR" };
-
-
-
-
-
- Random rnd = new Random();
- string path = "~/MeetingFiles/" +rnd.Next().ToString()+".ics";
- System.IO.File.WriteAllLines(Server.MapPath(path), contents);
-
-
-
-
-
-
-
- MailMessage mail = new MailMessage();
- mail.To.Add(tomailid);
-
- mail.From = new MailAddress("Your Mail Id");
- mail.Subject = "You have 1 scheduled Meeting";
- mail.CC.Add("Mail CC if any");
- mail.Attachments.Add(new Attachment(Server.MapPath(resume))); // attach the File
- Attachment mailAttachment = new Attachment(Server.MapPath(path));
- mail.Attachments.Add(mailAttachment);
-
-
- mail.Body = Body;
-
- mail.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient();
- smtp.Port = 587;
-
- smtp.Host = "outlook.office365.com";
- smtp.Credentials = new System.Net.NetworkCredential
- ("Your Id", "Your Password");
-
- smtp.EnableSsl = true;
- smtp.Send(mail);
-
- }
- catch (Exception ex)
- {
- }
- }