Send Meeting Request With C#

private void SendMeetingRequest()
        {
            SmtpClient sc = new SmtpClient("[smtp server address]");
            MailMessage msg = new MailMessage();
            msg.IsBodyHtml = true;
            
            msg.From = new MailAddress("[email protected]", "Test");
            msg.To.Add(new MailAddress("[email protected]", "Test"));
            msg.Subject = "Send Calendar Appointment Email";
            string path = upload.PostedFile.FileName;
           
            System.IO.Stream upLoadStream = upload.PostedFile.InputStream;

            System.Net.Mime.ContentType type = new System.Net.Mime.ContentType("text/html");
            LinkedResource lr = new LinkedResource(upLoadStream, "image/jpeg");
          
            lr.ContentId = "Image";
            msg.Body = "Here is the Body Content";
            //AlternateView view = AlternateView.CreateAlternateViewFromString(msg.Body + "<p><img src=cid:Image /></p>", type);
            AlternateView view = AlternateView.CreateAlternateViewFromString(msg.Body + "<p><img src='"+path+"' /></p>", type);
           
            view.LinkedResources.Add(lr);
            msg.AlternateViews.Add(view);
           // sc.Send(msg);//EMAIL

            StringBuilder str = new StringBuilder();
            str.AppendLine("BEGIN:VCALENDAR");
            str.AppendLine("PRODID:-//Test");
            str.AppendLine("VERSION:2.0");
            str.AppendLine("METHOD:REQUEST");
            str.AppendLine("BEGIN:VEVENT");
            str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", Convert.ToDateTime("2013.12.18 17:00:00")));
            str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
            str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", Convert.ToDateTime("2013.12.19 17:00:00")));
            str.AppendLine("LOCATION: Dubai");
            str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
            str.AppendLine(string.Format("DESCRIPTION:{0}", msg.Body));
            str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body));
            str.AppendLine(string.Format("SUMMARY:{0}", msg.Subject));
            str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", msg.From.Address));

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

            str.AppendLine("BEGIN:VALARM");
            str.AppendLine("TRIGGER:-PT15M");
            str.AppendLine("ACTION:DISPLAY");
            str.AppendLine("DESCRIPTION:Reminder");
            str.AppendLine("END:VALARM");
            str.AppendLine("END:VEVENT");
            str.AppendLine("END:VCALENDAR");
            System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
           // ct.Parameters.Add("method", "PUBLISH");
            ct.Parameters.Add("method", "REQUEST");
            ct.Parameters.Add("name", "Meeting.ics");
            AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
            msg.AlternateViews.Add(avCal);

            sc.Send(msg);//Meeting Request
        }

你可能感兴趣的:(Send Meeting Request With C#)