I'm using Google Calendar Api v3 for .Net in my project. I need to create event and send notification when any attendee replies to event ("Yes", "No"). I read the api documentation and tried what it says. Below is the code that i create service account credential and create event with organizer and creator information.
I have the domain "example.net" and trying to create event with organizer that has email "[email protected]" , both organizer and attendees can be from different domains like "gmail, outlook".
But whenever i create the event, api automatically sends email to attendees about event information, but organizer looks like "[email protected]" which is defined in "calendar.json" file. So whenever attendee replies the event, organizer cannot get email about what an attendee replied for event. I couldnt able to set organizer to "[email protected]", it is always "[email protected]".
Please look at the code below and tell me how can i set the organizer,creator of event to "[email protected]" (which also can be in different email address with different domain like gmail, outlook), or how can i make google calendar sends email notification to event organizer when any attendee replies to event (yes or no)
private static Event SendCalendarInvitation()
{
try
{
string credPath = @"C:\calendar.json";
var json = File.ReadAllText(credPath);
var cr = JsonConvert.DeserializeObject<PersonalServiceAccountCred>(json);
var xCred = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(cr.client_email)
{
Scopes = new[] {
CalendarService.Scope.Calendar
}
}.FromPrivateKey(cr.private_key));
// Create the service
CalendarService service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = xCred
});
Event calendarEvent = new Event
{
Summary = "Example Event",
Location = "Los Angeles",
Description = "Description",
Start = new EventDateTime()
{
DateTime = new DateTime(2018, 6, 2, 10, 0, 0),
TimeZone = "America/Los_Angeles"
},
End = new EventDateTime()
{
DateTime = new DateTime(2018, 6, 2, 12, 0, 0),
TimeZone = "America/Los_Angeles"
},
Attendees = new List<EventAttendee>()
{
new EventAttendee() { Email = "[email protected]", Organizer = true},
new EventAttendee() { Email = "[email protected]"}
},
Creator = new Event.CreatorData()
{
Email = "[email protected]",
DisplayName = "Organizer"
},
Organizer = new Event.OrganizerData()
{
Email = "[email protected]",
DisplayName = "Organizer"
},
Reminders = new Event.RemindersData()
{
UseDefault = false,
Overrides = new List<EventReminder>()
{
new EventReminder()
{
Method = "email",
Minutes = 30
},
new EventReminder()
{
Method = "email",
Minutes = 14400
}
}
}
};
Event calendarEventResult = null;
var statusCode = System.Net.HttpStatusCode.Accepted;
try
{
var request = service.Events.Insert(calendarEvent, "primary");
request.SendNotifications = true;
calendarEventResult = request.Execute();
}
catch (Exception ex)
{
statusCode = System.Net.HttpStatusCode.BadRequest;
}
return calendarEventResult;
}
catch (Exception ex)
{
return null;
}
}