如何使用ics文件和日历部分正确地向Outlook发送消息? [英] How to properly send a message to outlook with an ics file and calendar part?

查看:202
本文介绍了如何使用ics文件和日历部分正确地向Outlook发送消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要发送包含日历备用视图和相同.ics文件的电子邮件。当我发送没有任何附件的电子邮件时,日历
事件预览会很好地显示。但是当我添加任何类型的附件时,日历预览会消失,我只能看到附加预览。如何做到这两个部分是可见的。

只有在outlook.com的其他服务中,下面的代码才能完美。

It's only in outlook.com in other services the code below works perfect.

static void Main(string[] args)
    {
        var client = new SmtpClient();

        Console.WriteLine("connection success");
        // Now Contruct the ICS file using string builder
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("fromemail@gmail.com", "Sender's Name");
        msg.To.Add(new MailAddress("example@outlook.com", "To Name"));
        msg.Subject = "Send mail with ICS file as an Attachment";
        msg.Body = "Please Attend the meeting with this schedule";
        StringBuilder str = new StringBuilder();
        str.AppendLine("BEGIN:VCALENDAR");
        str.AppendLine("PRODID:-//Schedule a Meeting");
        str.AppendLine("VERSION:2.0");
        str.AppendLine("METHOD:REQUEST");
        str.AppendLine("BEGIN:VEVENT");
        str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddMinutes(+10)));
        str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
        str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddMinutes(+60)));
        str.AppendLine("LOCATION: CGI");
        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(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("BEGIN:VALARM");
        str.AppendLine("TRIGGER:-PT15M");
        str.AppendLine("ACTION:DISPLAY");
        str.AppendLine("DESCRIPTION:Reminder");
        str.AppendLine("END:VALARM");
        str.AppendLine("END:VEVENT");
        str.AppendLine("END:VCALENDAR");

        System.Net.Mime.ContentType contype = new System.Net.Mime.ContentType("text/calendar");
        contype.Parameters.Add("method", "REQUEST");
        contype.Parameters.Add("name", "Meeting.ics");
        AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), contype);
        msg.AlternateViews.Add(avCal);

        //Byte[] bytes = System.Text.Encoding.ASCII.GetBytes(str.ToString());
        //var ms = new System.IO.MemoryStream(bytes);            
        //msg.Attachments.Add(new Attachment(ms, contype));

        client.Send(msg);
        //ms.Close();
        Console.WriteLine("Sent");
        Console.ReadLine();
    }

推荐答案

嗨datrax,

Hi datrax,

>>只有在outlook.com的其他服务中,下面的代码才能完美。

>> It's only in outlook.com in other services the code below works perfect.

"outlook.com"是什么意思?你的意思是收件人的电子邮件地址是"outlook.com"吗?如果是这样,您能否分享我们如何打开电子邮件?你在Outlook在线,Outlook客户端或其他电子邮件客户端打开它吗?

What do you mean by "outlook.com"? Do you mean the email address of the receiver is "outlook.com"? If so, could you share us how you open the email? Do you open it in Outlook online, outlook client or with other email client?

最好的问候,

Edward


这篇关于如何使用ics文件和日历部分正确地向Outlook发送消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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