Exemple #1
0
        public void SendMail()
        {
            MailMessage mail = new MailMessage("*****@*****.**", "*****@*****.**");

            mail.Subject = "Coucou";
            mail.Body    = "Salut";

            Event myEvent = new Event();

            myEvent.UID       = "Test-01";
            myEvent.Location  = "Brussels";
            myEvent.Status    = EventStatus.CONFIRMED;
            myEvent.Organizer = new Organizer()
            {
                PublicName = "Thierry THOUA", Email = "*****@*****.**"
            };
            myEvent.StartTime = new DateTime(2011, 7, 1, 17, 0, 0);
            myEvent.EndTime   = new DateTime(2011, 7, 1, 19, 0, 0);
            myEvent.Attendees.Add(new Attendee()
            {
                PublicName = "Jojo Lapin", Email = "*****@*****.**", Role = Role.OPTPARTICIPANT
            });
            myEvent.Description = "Voici une conf";
            myEvent.Title       = "Conference about ics";

            mail.AddEvent(myEvent);
        }
        public Task <ActionResult> Sendmail(string to, string subj, string body, MeetingViewModel meet, Event nEvent)
        {
            SmtpClient smtpClient = new SmtpClient(MvcApplication.set.AuthDnAddress, 25)
            {
                UseDefaultCredentials = false,
                EnableSsl             = true,
                Credentials           = new NetworkCredential(MvcApplication.set.SmtpLogin, MvcApplication.set.SmtpPassword),

                DeliveryMethod = SmtpDeliveryMethod.Network,
                Timeout        = 20000
            };
            MailMessage mailMessage = new MailMessage()
            {
                Priority = MailPriority.High,
                From     = new MailAddress("*****@*****.**", "Планировщик системы видео-конференц-связи 'Сова'")
            };
            AlternateView alternateHtml = AlternateView.CreateAlternateViewFromString(body,
                                                                                      new ContentType("text/html"));

            mailMessage.AlternateViews.Add(alternateHtml);
            mailMessage.To.Add(new MailAddress(to));
            mailMessage.Subject = subj;
            mailMessage.Body    = body;

            //Event myEvent = new Event();

            mailMessage.AddEvent(nEvent);


            #region Method 1

            //StringBuilder str = new StringBuilder();
            //str.AppendLine("BEGIN:VCALENDAR");

            ////PRODID: identifier for the product that created the Calendar object
            //str.AppendLine("PRODID:-//ABC Company//Outlook MIMEDIR//EN");
            //str.AppendLine("VERSION:2.0");
            //str.AppendLine("METHOD:REQUEST");

            //str.AppendLine("BEGIN:VEVENT");

            //str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", meet.Start));
            //    //TimeZoneInfo.ConvertTimeToUtc("BeginTime").ToString("yyyyMMddTHHmmssZ")));
            //str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
            //str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", meet.End));
            //    //TimeZoneInfo.ConvertTimeToUtc("EndTime").ToString("yyyyMMddTHHmmssZ")));
            //str.AppendLine(string.Format("LOCATION: {0}", "Система ВКС 'Сова'"));

            //// UID should be unique.
            //str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
            //str.AppendLine(string.Format("DESCRIPTION:{0}", mailMessage.Body));
            //str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", mailMessage.Body));
            //str.AppendLine(string.Format("SUMMARY:{0}", mailMessage.Subject));

            //str.AppendLine("STATUS:CONFIRMED");
            //str.AppendLine("BEGIN:VALARM");
            //str.AppendLine("TRIGGER:-PT15M");
            //str.AppendLine("ACTION:Accept");
            //str.AppendLine("DESCRIPTION:Reminder");
            //str.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY");
            //str.AppendLine("END:VALARM");
            //str.AppendLine("END:VEVENT");

            //str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", mailMessage.From.Address));
            //str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", mailMessage.To[0].DisplayName,
            //    mailMessage.To[0].Address));

            //str.AppendLine("END:VCALENDAR");
            //ContentType ct = new ContentType("text/calendar");
            //ct.Parameters.Add("method", "REQUEST");
            //ct.Parameters.Add("name", "meeting.ics");
            //AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
            //mailMessage.AlternateViews.Add(avCal);

            #endregion


            smtpClient.Send(mailMessage);
            return(null);
        }