使用C#发送Outlook会议请求 [英] Send an Outlook Meeting Request with C#

查看:391
本文介绍了使用C#发送Outlook会议请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望从C#发送一个Outlook会议请求. 我有下面的代码可以做到这一点,但是.

I am looking to send an outlook Meeting Request from C#. i have the code below that it do the job but.

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);

发送邀请时,它需要用户接受,当用户接受邀请时,Outlook日历将状态显示为
有什么方法可以发送不需要用户接受邀请并且Outlook日历显示为不在办公室"的邀请? 我已经尝试过这两个部分,但没有运气

when the invitation is send, it need the user to accept the invitation, and when the user accept the invitation, Outlook calendar shows the status as BUSY
is there any way to send the invitation that does not require user to accept it and the Outlook calendar shows as Out Of Office ? i have tried with this 2 part but no luck

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

推荐答案

如果这是资源邮箱,则可以将其配置为自动接受会议邀请(文件|选项|日历|自动接受或拒绝).

If this is a resource mailbox, you can configure it to auto accept meeting invitations (File | Options | Calendar | Automatic Accept or Decline).

如果这是一个任意邮箱,那么在没有所有者允许的情况下不会发生任何事情.如果您有用户凭据,则最好的办法是使用Outlook对象模型/EWS/MAPI直接访问邮箱.

If this is an arbitrary mailbox, nothing happens without the owner's permission. The best you can do is directly access the mailbox using the Outlook Object Model / EWS/ MAPI if you have the user credentials.

这篇关于使用C#发送Outlook会议请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆