Here's what I ended up using... Not ideal, but works alright.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Exchange.WebServices.Autodiscover;
using System.Net;
namespace program
{
class Program
{
static void Main(string[] args)
{
// Connect to Office 365 Exchange
ExchangeService service = new ExchangeService();
NetworkCredential ncNetworkCredential = new NetworkCredential("user@example", "password", "");
service.Credentials = ncNetworkCredential;
service.AutodiscoverUrl("user@example", delegate { return true; });
// Connect to shared mailbox and get the folder id of the calendar
Mailbox mb = new Mailbox("user@example.com");
FolderId fid = new FolderId(WellKnownFolderName.Calendar, mb);
// Create a string to hold all of the email content...
String emailBody = "";
emailBody += "<p style=\"font-size:10pt; color: #AAA;text-align:center;\">Please do not reply to this email.</p>";
// Create a weekly calendar view...
CalendarView view = new CalendarView(DateTime.Now.AddDays(1).AddHours(-7),DateTime.Now.AddDays(8));
FindItemsResults<Appointment> results = service.FindAppointments(fid, view);
// Look through the appointments of the week.
for (int i = 0; i < results.Items.Count; i++)
{
try
{
// Add text to the email body.
emailBody += "<p>";
emailBody += "Task: " + results.Items[i].Subject.ToString() + "<br />";
emailBody += "Resource: " + results.Items[i].Location.ToString() + "<br />";
emailBody += "Date: " + results.Items[i].Start.ToShortDateString() + " " + results.Items[i].Start.ToShortTimeString() + "<br />";
emailBody += "</p>";
}
catch
{
// Add text to the email body.
emailBody += "<p>";
emailBody += "Task: " + results.Items[i].Subject.ToString() + "<br />";
//emailBody += "Resource: " + results.Items[i].Location.ToString() + "<br />";
emailBody += "Date: " + results.Items[i].Start.ToShortDateString() + " " + results.Items[i].Start.ToShortTimeString() + "<br />";
emailBody += "</p>";
}
}
// Line referencing the calendar.
emailBody += "<p style=\"color: red;text-align:center;\">For more information on tasks check the \"calendar\"</p>";
// Create a new email message.
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("user@example.com");
email.Subject = "Scheduled Tasks (" + DateTime.Now.ToShortDateString() + ")";
email.Body = emailBody;
try
{
email.Send();
}
catch (Exception e)
{
Console.WriteLine("Error: " + e);
}
}
}
}
1Can you explain your code, and how you implemented it? If not, how is this supposed to help others looking to solve the same problem you presented in your question? Why isn't it "ideal"? – Ƭᴇcʜιᴇ007 – 2013-12-24T22:46:46.763