2014-12-09 21 views
6

Sto cercando di inviare una richiesta di riunione Outlook da C#. ho il codice qui sotto che fa il lavoro ma.Invia una richiesta di riunione di Outlook con C#

string startTime1 = Convert.ToDateTime(startTime).ToString("yyyyMMddTHHmmssZ"); 
string endTime1 = Convert.ToDateTime(endTime).ToString("yyyyMMddTHHmmssZ"); 
SmtpClient sc = new SmtpClient(""); 

MailMessage msg = new MailMessage(); 

msg.From = new MailAddress("", "HR Self Service"); 
msg.To.Add(new MailAddress(emailto)); 
msg.Subject = "Holiday Approval"; 
msg.Body = emailbody; 

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}", startTime1));//TimeZoneInfo.ConvertTimeToUtc("BeginTime").ToString("yyyyMMddTHHmmssZ"))); 
str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow)); 
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", endTime1));//TimeZoneInfo.ConvertTimeToUtc("EndTime").ToString("yyyyMMddTHHmmssZ"))); 
str.AppendLine(string.Format("LOCATION: {0}", "Location")); 

// UID should be unique. 
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("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}", msg.From.Address)); 
str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[0].DisplayName, msg.To[0].Address)); 

str.AppendLine("END:VCALENDAR"); 
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar"); 
ct.Parameters.Add("method", "REQUEST"); 
ct.Parameters.Add("name", "meeting.ics"); 
AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct); 
msg.AlternateViews.Add(avCal); 
//Response.Write(str); 
// sc.ServicePoint.MaxIdleTime = 2; 
sc.Send(msg); 

quando l'invito viene inviato, è necessario che l'utente accettare l'invito, e quando l'utente accetta l'invito, calendario di Outlook mostra lo stato come OCCUPATO
c'è un modo per inviare il invito che non richiede all'utente di accettarlo e il calendario di Outlook mostra come Fuori sede? ho provato con questo 2 parte ma senza fortuna

str.AppendLine("ACTION:Accept"); 
str.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY"); 
+0

È una domanda ben formata. Tuttavia, non riesco a immaginare che Exchange possa consentire a qualsiasi vecchio messaggio SMTP di accettare automaticamente una richiesta di riunione. – itsme86

+0

itsme86 Grazie per il commento, c'è qualche nuovo SMTP che mi consente di inviare e-mail che accetterà automaticamente una richiesta di riunione? –

+0

Non SMTP, ma avete mai visitato Exchange Web Services (EWS)? http://msdn.microsoft.com/en-us/library/office/dd877045%28v=exchg.140%29.aspx – itsme86

risposta

1

Se questa è una cassetta postale delle risorse, è possibile configurarlo per l'auto di accettare inviti alle riunioni (File | Opzioni | Calendario | Accetta automatico o Rifiuta).

Se questa è una cassetta postale arbitraria, non accade nulla senza il permesso del proprietario. Il meglio che puoi fare è accedere direttamente alla casella di posta usando Outlook Object Model/EWS/MAPI se hai le credenziali dell'utente.

Problemi correlati