none
Send a Task/Todo List to Outlook Using C# SMTP RRS feed

  • Question

  • Hi,

    I have the below code inside sendtask method.

     DateTime start = DateTime.Parse("Jan 1, 2005");
                DateTime end = DateTime.Parse("Jan 2, 2005");
                SmtpClient sc = new SmtpClient();
                sc.Host = System.Configuration.ConfigurationManager.AppSettings["SMTP-Host"].ToString();
                sc.EnableSsl = true;
                NetworkCredential NetworkCred = new NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["SMTP-Username"].ToString(), System.Configuration.ConfigurationManager.AppSettings["SMTP-Password"].ToString());
                sc.Port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SMTP-Port"].ToString());
                sc.UseDefaultCredentials = false;
                sc.Credentials = NetworkCred;
                MailMessage msg = new MailMessage();

                msg.From = new MailAddress("test@gmail.com");

                foreach (var address in task.Attendees.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                {
                    msg.To.Add(address);
                }
                msg.Subject = task.Title;
                msg.Body = task.Description;

                StringBuilder str = new StringBuilder();
                str.AppendLine("BEGIN:VCALENDAR");
                str.AppendLine("PRODID:-//ABC Company//Outlook MIMEDIR//EN");
                str.AppendLine("VERSION:2.0");
                str.AppendLine("METHOD:REQUEST");
                str.Append("BEGIN:VTODO");
                 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("DTSTART:");
                string hour = start.Hour.ToString();
                if (hour.Length < 2) { hour = "0" + hour; }

                string min = start.Minute.ToString();
                if (min.Length < 2) { min = "0" + min; }

                string sec = start.Second.ToString();
                if (sec.Length < 2) { sec = "0" + sec; }

                string mon = start.Month.ToString();
                if (mon.Length < 2) { mon = "0" + mon; }

                string day = start.Day.ToString();
                if (day.Length < 2) { day = "0" + day; }

                str.AppendLine(start.Year.ToString() + mon + day
                                       + "T" + hour + min + sec);
                str.AppendLine("\n");

                //DTEND
                str.AppendLine("DTEND:");
                hour = end.Hour.ToString();
                if (hour.Length < 2) { hour = "0" + hour; }

                min = end.Minute.ToString();
                if (min.Length < 2) { min = "0" + min; }

                sec = end.Second.ToString();
                if (sec.Length < 2) { sec = "0" + sec; }

                mon = end.Month.ToString();
                if (mon.Length < 2) { mon = "0" + mon; }

                day = end.Day.ToString();
                if (day.Length < 2) { day = "0" + day; }

                str.AppendLine(end.Year.ToString() + mon +
                             day + "T" + hour + min + sec);
                str.AppendLine("\n");

                //Location
                str.AppendLine("LOCATION;ENCODING=QUOTED-PRINTABLE: "
                                                         + String.Empty);
                str.AppendLine("\n");

                //Message body
                str.AppendLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:"
                                                                + task.Description);
                str.AppendLine("\n");

                //Subject
                str.AppendLine("SUMMARY;ENCODING=QUOTED-PRINTABLE:"
                                                                + task.Title);
                str.AppendLine("END:VTODO");
                str.AppendLine("END:VALARM");
                str.AppendLine("END:VCALENDAR");
                str.AppendLine("\n");
                sc.Send(msg);

    But it is sending a message to outlook instead of pointing to Tasks folder in Outlook.It does not create a task/todolist in outlook.Please help me on this.

    Thursday, December 8, 2016 11:41 AM

All replies

  • The MIME Content-Type header must be set correctly.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, December 8, 2016 3:40 PM
  • Hello Pradeep,

    You can create a corresponding item in Outlook manually and then save it to the disk. Then you can compare items and find what should be done to fix the issue.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Sunday, December 11, 2016 8:47 PM