Exemplo n.º 1
0
        /// <summary>
        /// Send mail ICalendar
        /// </summary>
        /// <param name="mailMeetingEntity">MailMeetingEntity</param>
        /// <param name="actionBeforeSendMeeting">Action<MailMessage></param>
        public string SendMeeting(MailMeetingEntity mailMeetingEntity, Action <MailMessage> actionBeforeSendMeeting)
        {
            SmtpClient m_SmtpClient = new SmtpClient();

            if (this.MailConfig != null)
            {
                m_SmtpClient.UseDefaultCredentials = MailConfig.UseDefaultCredentials;
                if (!MailConfig.UseDefaultCredentials) //tạo mới Smtp Credentials
                {
                    m_SmtpClient.Credentials = new NetworkCredential(MailConfig.Username, MailConfig.Password, MailConfig.Domain);
                }
                m_SmtpClient.Port      = MailConfig.Port;
                m_SmtpClient.Host      = MailConfig.Host;
                m_SmtpClient.EnableSsl = MailConfig.EnableSsl;
            }

            MailMessage m_MailMessage = new MailMessage()
            {
                From       = new MailAddress(mailMeetingEntity.From),
                Body       = mailMeetingEntity.Body,
                Subject    = mailMeetingEntity.Subject,
                IsBodyHtml = true,
            };

            //Parse MailMeetingEntity -> ICalendar Entity

            // Create a new iCalendar
            iCalendar m_iCalendar = new iCalendar()
            {
                Method    = MailServiceICal.ICalendarMethod_Request, //PUBLISH THÌ KO ADD VÀO TRONG CALENDAR
                Version   = MailServiceICal.ICalendar_Version,
                ProductID = MailServiceICal.ICalendar_ProductID,
            };

            // Create the event, and add it to the iCalendar
            Event m_Event = m_iCalendar.Create <Event>();

            // Set information about the event
            m_Event.UID         = mailMeetingEntity.UID;
            m_Event.DTStamp     = new iCalDateTime(mailMeetingEntity.Stamp);
            m_Event.Start       = new iCalDateTime(mailMeetingEntity.Start);
            m_Event.End         = new iCalDateTime(mailMeetingEntity.End);
            m_Event.Description = mailMeetingEntity.Description;
            m_Event.Location    = mailMeetingEntity.Location;
            m_Event.Summary     = mailMeetingEntity.Description;
            //m_event.Transparency = TransparencyType.Opaque;

            //CONFIG ALARM
            foreach (var m_AlarmEntity in mailMeetingEntity.Alarms)
            {
                AlarmAction m_AlarmAction = new AlarmAction();
                if (m_AlarmEntity.Trigger.Equals(MailServiceICal.Action_Audio))
                {
                    m_AlarmAction = AlarmAction.Audio;
                }
                else if (m_AlarmEntity.Trigger.Equals(MailServiceICal.Action_Display))
                {
                    m_AlarmAction = AlarmAction.Display;
                }
                else if (m_AlarmEntity.Trigger.Equals(MailServiceICal.Action_Email))
                {
                    m_AlarmAction = AlarmAction.Email;
                }
                else if (m_AlarmEntity.Trigger.Equals(MailServiceICal.Action_Procedure))
                {
                    m_AlarmAction = AlarmAction.Procedure;
                }
                m_Event.Alarms.Add(new Alarm
                {
                    Duration    = m_AlarmEntity.Duration,
                    Trigger     = new Trigger(m_AlarmEntity.Trigger),
                    Description = m_AlarmEntity.Description,
                    Repeat      = m_AlarmEntity.RepeatTime,
                    Action      = m_AlarmAction,
                });
            }

            //Add Attendees
            var m_Attendes = new List <IAttendee>();

            foreach (var m_AttendeesEntity in mailMeetingEntity.Attendees)
            {
                m_MailMessage.To.Add(new MailAddress(m_AttendeesEntity.Email));
                IAttendee m_Attendee = new DDay.iCal.Attendee(MailServiceICal.Attendee_MailTo + m_AttendeesEntity.Email);
                if (m_AttendeesEntity.IsOptional)
                {
                    m_Attendee.Role = MailServiceICal.Role_Optional;
                }
                else
                {
                    m_Attendee.Role = MailServiceICal.Role_Request;
                }
                m_Attendes.Add(m_Attendee);
            }

            if (m_Attendes != null && m_Attendes.Count > 0)
            {
                m_Event.Attendees = m_Attendes;
            }

            //Check before send meeting
            if (actionBeforeSendMeeting != null)
            {
                actionBeforeSendMeeting(m_MailMessage);
            }

            DDay.iCal.Serialization.iCalendar.iCalendarSerializer m_Serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer();
            //Convert iCal to string
            string m_iCalendarData = m_Serializer.SerializeToString(m_iCalendar);

            System.Net.Mime.ContentType m_Contype = new System.Net.Mime.ContentType(MailServiceICal.ICalendar_ContentType);
            m_Contype.Parameters.Add(MailServiceICal.ICalendar_Method, MailServiceICal.ICalendarMethod_Request);
            m_Contype.Parameters.Add(MailServiceICal.ICalendar_Name, MailServiceICal.ICalendar_FileName);
            AlternateView m_AlternateView = AlternateView.CreateAlternateViewFromString(m_iCalendarData, m_Contype);

            m_MailMessage.AlternateViews.Add(m_AlternateView);

            m_SmtpClient.Send(m_MailMessage);
            return(m_iCalendarData);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Send mail ICalendar
 /// </summary>
 /// <param name="mailMeetingEntity">MailMeetingEntity</param>
 public string SendMeeting(MailMeetingEntity mailMeetingEntity)
 {
     return(this.SendMeeting(mailMeetingEntity, null));
 }