public bool CheckDateElements(SendMeetingInvite meetingInfo)
 {
     if (meetingInfo.STARTDTE == null || meetingInfo.STARTTIME == null)
         return false;
     if (meetingInfo.ENDDTE != null && meetingInfo.ENDTIME == null)
         return false;
     if (meetingInfo.ENDDTE == null && meetingInfo.ENDTIME != null)
         return false;
     if (meetingInfo.IsRecurring != null && meetingInfo.IsRecurring == "2" && meetingInfo.Duration == null)
         return false;
     if (meetingInfo.IsRecurring != null && meetingInfo.IsRecurring == "2" && meetingInfo.RecurrenceCount == null)
         return false;
     if (meetingInfo.IsRecurring != null && meetingInfo.IsRecurring == "2" && meetingInfo.FreqId == null)
         return false;
     //All good..
     return true;
 }
        public genericResponse SendMeetingInviteNow(SendMeetingInvite meetingInfo)
        {
            genericResponse _response;
            try
            {
                #region [[ Basic Check Here...]]
                if (meetingInfo != null
                    && !string.IsNullOrEmpty(meetingInfo.SUBJECT)
                    && !string.IsNullOrEmpty(meetingInfo.MESSAGE)
                    //To Address Option....
                    && (!string.IsNullOrEmpty(meetingInfo.RCPNTS) || CheckRecipientsExist(meetingInfo.userEmailGroups))
                    && CheckDateElements(meetingInfo))
                {

                    #region [[ Continue as we are good...]]
                    bool IsMessageSent = false;
                    string _file_path = "";
                    var sendEmails = Convert.ToBoolean(ConfigurationManager.AppSettings["General.SendBlastEmails"]);
                    //Let us gather Information for sending Email out...
                    var client = new SmtpClient();
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.UseDefaultCredentials"].ToString()))
                        client.UseDefaultCredentials = true;
                    client.Host = ConfigurationManager.AppSettings["Server.Hostname"].ToString();// "smtp.cso.local";
                    client.Port = int.Parse(ConfigurationManager.AppSettings["Server.Port"].ToString());//25;
                    //client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.CredentialsRequired"].ToString()))
                        client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Server.Username"].ToString(), ConfigurationManager.AppSettings["Server.Password"].ToString());
                    //Now set up MailMessage
                    MailMessage message = new MailMessage();
                    message.IsBodyHtml = true;
                    //From Address
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.CredentialsRequired"].ToString()))
                    {
                        message.From = new MailAddress("*****@*****.**");
                    }
                    else
                    {
                        message.From = new MailAddress(CurrentUser.EmailAdress);
                    }
                    //Subject
                    message.Subject = meetingInfo.SUBJECT.Trim();
                    //Meeting type and Recurrency Freq Type
                    string meetingType = uow.EmailRepository().GetMeetingTypeName(Convert.ToInt32(meetingInfo.TypeId));
                    string RecurrenceFrequency = "";
                    if (!string.IsNullOrEmpty(meetingInfo.FreqId))
                    {
                        RecurrenceFrequency = uow.EmailRepository().GetMeetingFreqTypeName(Convert.ToInt32(meetingInfo.FreqId));
                    }
                    //For HTML Body
                    string bodyText = "Meeting Type: {0}\r\n\r\n</br></br>{1}";
                    bodyText = string.Format(bodyText, meetingType, meetingInfo.MESSAGE.Trim().Replace("\r\n", "<br/>").Replace(" ", "&nbsp;"));
                    AlternateView body = AlternateView.CreateAlternateViewFromString(bodyText, new ContentType("text/html"));
                    message.AlternateViews.Add(body);

                    System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
                    //Check if event is Rercurring type
                    if (meetingInfo.IsRecurring == null || meetingInfo.IsRecurring == "1")
                    {
                        AlternateView avCal =
                            AlternateView.CreateAlternateViewFromString(CreateCalendarEvent(message.Subject,
                            meetingInfo.MESSAGE.Trim().Replace("\r\n", "<br/>").Replace(" ", "&nbsp;"),
                            GetDateAndTimeTogether(Convert.ToDateTime(meetingInfo.STARTDTE), meetingInfo.STARTTIME.ToString()),
                            GetDateAndTimeTogether(Convert.ToDateTime(meetingInfo.ENDDTE), meetingInfo.ENDTIME.ToString()),
                            meetingInfo.LOCATION.Trim(),
                            message.From.Address,
                            null,
                            false), ct);
                        message.AlternateViews.Add(avCal);
                    }
                    else
                    {
                        //For recurring Event...
                        AlternateView avCal = AlternateView.CreateAlternateViewFromString(CreateCalendarEvent(message.Subject,
                            meetingInfo.MESSAGE.Trim().Replace("\r\n", "<br/>").Replace(" ", "&nbsp;"),
                            GetDateAndTimeTogether(Convert.ToDateTime(meetingInfo.STARTDTE), meetingInfo.STARTTIME.ToString()),
                            Convert.ToDouble(meetingInfo.Duration),
                            meetingInfo.LOCATION.Trim(),
                            message.From.Address,
                            null,
                            false,
                            GetRecurrenceDayInterval(RecurrenceFrequency),
                            Convert.ToInt32(meetingInfo.RecurrenceCount),
                            RecurrenceFrequency), ct);
                        message.AlternateViews.Add(avCal);
                    }

                    //Set To Address as From by default
                    message.To.Add(message.From);
                    //For Entered Email Addresses
                    if (!string.IsNullOrEmpty(meetingInfo.RCPNTS))
                    {
                        //We also have email address entered here
                        string[] receiverAddress = meetingInfo.RCPNTS.Trim().Split(',');
                        foreach (string address in receiverAddress)
                        {
                            //Add Address as To
                            if (Validation.ValidateEmail(address.Trim()))
                            {
                                message.To.Add(new MailAddress(address.Trim()));
                            }
                        }
                    }
                    //For User Grooup if any selected .....
                    foreach (EmailGroups usrg in meetingInfo.userEmailGroups)
                    {
                        if (usrg.IsSelected)
                        {
                            emailAdrsInfo = null;
                            emailAdrsInfo = uow.EmailRepository().GetUserEmailGroupAddresses(Convert.ToInt32(usrg.Id)).ToList();
                            message = AddAddresses(emailAdrsInfo, message);
                        }
                    }

                    //For Attachement...
                    if (!string.IsNullOrEmpty(meetingInfo.FILENAMES))
                    {
                        //Now save the file in the tmp folder
                        _file_path = System.Web.Hosting.HostingEnvironment.MapPath("~");
                        if (_file_path.Substring(_file_path.Length) != "\\")
                        {
                            _file_path += "\\";
                        }
                        _file_path += "Uploads\\" + meetingInfo.FILENAMES;

                        using (System.IO.FileStream fileStream = new System.IO.FileStream(_file_path, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            System.Net.Mail.Attachment _attachment = new System.Net.Mail.Attachment(fileStream, meetingInfo.FILENAME, MediaTypeNames.Application.Octet);
                            // Add time stamp information for the file.
                            ContentDisposition disposition = _attachment.ContentDisposition;
                            disposition.CreationDate = System.IO.File.GetCreationTime(_file_path);
                            disposition.ModificationDate = System.IO.File.GetLastWriteTime(_file_path);
                            disposition.ReadDate = System.IO.File.GetLastAccessTime(_file_path);
                            // Add the file attachment to this e-mail message.
                            message.Attachments.Add(_attachment);

                            //Send the message with Attachment
                            if (sendEmails)
                            {
                                client.Timeout = 30000000;
                                client.Send(message);
                                IsMessageSent = true;
                            }
                        }
                        //Now delete attachment
                        File.Delete(_file_path);
                    }
                    //Send the message for non-Attachment Messages...
                    if (sendEmails && !IsMessageSent)
                    {
                        client.Timeout = 30000000;
                        client.Send(message);
                    }
                    #endregion
                    _response = new genericResponse() { success = true };

                }
                else
                {
                    _response = new genericResponse() { success = false, message = "Required information is missing. Please check and correct your entry to proceed." };
                }
                #endregion
                //Back
                return _response;
            }
            catch (Exception ex)
            {
                _response = new genericResponse() { success = false, message = "There is a problem in sending the Email message. Please try again later. " + ex.Message };
                return _response;
            }
        }