Firstly, let me explain you what is .ics file/icalendar. It is a computer file format which allows Internet users to send meeting requests and tasks to other Internet users, via email, or sharing files with an extension of .ics. Recipients of the iCalendar data file can respond to the sender easily or counter-propose another meeting date/time as per the requirement.
Moreover, icalendar format is used by several email and calendar programs, including Microsoft Outlook, Google Calendar, and Apple iCal. It enables users to publish and share calendar information on the Web and over email; often used for sending meeting requests to other users, who can import the events into their own calendars. iCalendar files are saved in a plain text format. They contain information such as the title, summary, start time, and end time for the calendar event. The iCalendar format also supports event updates and cancellations.
Declaring of variables:
string strBody = "<html><body>" + "Some Text" + " <br/>" + " </body></html>";
string strBody = "Some Subject";
string strSubject= strBody.Replace("<html><body>", "");strDesc = strDesc + "To add this appointment to your calendar, please open and save the attached file." +
" </body></html>";
strDesc = strDesc.Replace("<br/>", @"\n");
strDesc = strDesc.Replace("<br/><br/>", @"\n");
strDesc = strDesc.Replace("</body></html>", "");
string strLocation = "Some Location";
DateTime schBeginDate = Convert.ToDateTime("StartDate"+ " " + "StartTime");
DateTime schEndDate = Convert.ToDateTime("EndDate" + " " + "EndTime");
PUTTING THE MEETING DETAILS INTO AN ARRAY OF STRING
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:" + strLocation,
"DESCRIPTION;ENCODING=ESCAPED-CHAR:" + strDesc,
"SUMMARY:" + strSubject,
"PRIORITY:3",
"END:VEVENT",
"END:VCALENDAR"
};
/*
* THE METHOD 'WriteAllLines' CREATES A FILE IN THE SPECIFIED PATH WITH
* THE SPECIFIED NAME,WRITES THE ARRAY OF CONTENTS INTO THE FILE AND CLOSES THE
* FILE.SUPPOSE THE FILE ALREADY EXISTS IN THE SPECIFIED LOCATION,THE CONTENTS
* IN THE FILE ARE OVERWRITTEN
*/
System.IO.File.WriteAllLines(HttpContext.Current.Server.MapPath("FileName.ics"), contents);
//MAKE AN ATTACHMENT OUT OF THE .ICS FILE CREATED
Attachment mailAttachment = new Attachment(HttpContext.Current.Server.MapPath("FileName.ics"));
//ADD THE ATTACHMENT TO THE EMAIL
mailMessage.Attachments.Add(mailAttachment);
Steps to send an email
string FromName = "From Name";
string FromEmail = "fromname@domain.com";string ToName = "To Name";
string ToEmail = "toname@domain.com";
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = false;
mailMessage.From = new MailAddress(FromEmail, FromName);
mailMessage.To.Add(new MailAddress(ToEmail, ToName));
mailMessage.Bcc.Add(new MailAddress("someemail@domain.com", "Some Name"));
if (strText != "")
{
strBody = strBody.Replace(" </body></html>", strText);
}
mailMessage.Subject = strSubject;
mailMessage.Body = strBody;
mailMessage.IsBodyHtml = true;
smtp.Host = "smtp.domain.net";
smtp.Send(mailMessage);
No comments:
Post a Comment