为什么我的icalcalendar不能被gmail识别?

本文关键字:gmail 识别 不能 我的 icalcalendar 为什么 | 更新日期: 2023-09-27 18:15:17

我的gmail和我的iCalendar有一个问题,这是一个简单的iCalendar:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//www.notilus.com//Dimo Gestion Notilus//FR
CALSCALE:GREGORIAN
METHOD:REQUEST
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VEVENT
DTSTART:20140619T080132Z
DTEND:20140619T090132Z
DTSTAMP:20140619T080132Z
ORGANIZER;CN=gonzo@work:mailto:gonzo@work
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
 FALSE;CN=gonzo@home;X-NUM-GUESTS=0:mailto:gonzo@home
CREATED:20140619T080132Z
DESCRIPTION:Description of flying to Sligo
X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//E
 N">'n<html>'n<body>'n<table border="1"><tr><td>'n<b>HTML</b> Description o
 f flying to Sligo'n</td></tr><tr><td>'n<ul><li>HTML has certain advantages
 </li></ul>'n</td></tr></table>'n</body>'n</html>
LAST-MODIFIED:20140619T080132Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Fly to Sligo
TRANSP:OPAQUE
UID:20140619T080132Z
END:VEVENT
END:VCALENDAR

如果我直接从gmail中附加,一切都可以工作。

如果我从我的网站发送,它不会。

这里是我的代码:

        using (var smtp = new SmtpClient())
        {
            var subject = "Confirm";
            var message = new MailMessage();
            message.To.Add(email);
            message.Subject = subject;
            var loCalendarType = new System.Net.Mime.ContentType();
            loCalendarType.MediaType = "text/calendar";
            loCalendarType.Parameters.Add("method", "REQUEST");
            loCalendarType.CharSet = @"""utf-8""";
            loCalendarType.Name = "event.ics";
            // Create message body parts
            var loCalendarView = AlternateView.CreateAlternateViewFromString(ical, loCalendarType);
            loCalendarView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
            message.AlternateViews.Add(loCalendarView);
            // html
            message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, Encoding.UTF8, System.Net.Mime.MediaTypeNames.Text.Html));
            smtp.Send(message);
        }

,这是mime发送:

Delivered-To: xxx@yyy.zzz
Received: by 10.217.130.201 with SMTP id dv51csp438169web;
        Mon, 28 Jul 2014 03:31:02 -0700 (PDT)
X-Received: by 10.194.243.200 with SMTP id xa8mr47346727wjc.97.1406543462611;
        Mon, 28 Jul 2014 03:31:02 -0700 (PDT)
Return-Path: <yyy@gmail.com>
Received: from mail-wg0-x22c.google.com (mail-wg0-x22c.google.com [2a00:1450:400c:c00::22c])
        by mx.google.com with ESMTPS id s3si12813117wic.21.2014.07.28.03.31.02
        for <xxx@yyy.zzz>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 28 Jul 2014 03:31:02 -0700 (PDT)
Received-SPF: pass (google.com: domain of yyy@gmail.com designates 2a00:1450:400c:c00::22c as permitted sender) client-ip=2a00:1450:400c:c00::22c;
Authentication-Results: mx.google.com;
       spf=pass (google.com: domain of yyy@gmail.com designates 2a00:1450:400c:c00::22c as permitted sender) smtp.mail=yyy@gmail.com;
       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Received: by mail-wg0-f44.google.com with SMTP id m15so7011538wgh.3
        for <xxx@yyy.zzz>; Mon, 28 Jul 2014 03:31:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=message-id:date:mime-version:from:to:subject:content-type
         :content-transfer-encoding;
        bh=3k0Ih6rGieP/qB5GSChSJva4900sXW0sQFSUWVfWfbk=;
        b=YiK7r5XcO9llXe9ek1NVyZnSifa1qie9Twk7dwnTsa90+xOrRrDb4VI2VUnJv4QRHm
         kOE4s/SUiXZpzZBA5Eiqc2cygxn2H5i4+tVEx6bV0MggqG4A+YfbhEkR5aP2EzaOdOy5
         cozy5HDBpdYv1AFpcGIOrQz0vJs4OIUTi4lZTw57ViM/PwxzkCDcseOPezGWoFXjXCBK
         8p+IV4JWn/b7uuu/BK/ZNcawES72OgwkVx9aqL6m/gz3wJuF4Qh5orxcqWvO7L2T5R8M
         s+7hLBpHY8Os0U2EBa/wmihhdWj1RdnZlwntfdGTMJB5SnFD6J1WWFzlrzXzScHxVMsP
         +9UA==
X-Received: by 10.180.24.66 with SMTP id s2mr29127288wif.33.1406543460817;
        Mon, 28 Jul 2014 03:31:00 -0700 (PDT)
Return-Path: <yyy@gmail.com>
Received: from max-pc ([80.86.155.45])
        by mx.google.com with ESMTPSA id lh15sm29883233wic.10.2014.07.28.03.30.59
        for <xxx@yyy.zzz>
        (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
        Mon, 28 Jul 2014 03:30:59 -0700 (PDT)
Message-ID: <53d62663.afcdb40a.4c38.ffffd877@mx.google.com>
Date: Mon, 28 Jul 2014 03:30:59 -0700 (PDT)
X-Google-Original-Date: 28 Jul 2014 12:30:54 +0200
MIME-Version: 1.0
From: yyy@gmail.com
To: xxx@yyy.zzz
Subject: Confirm
Content-Type: text/calendar; method=REQUEST
Content-Transfer-Encoding: 7bit
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//www.notilus.com//Dimo Gestion Notilus//FR
CALSCALE:GREGORIAN
METHOD:REQUEST
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VEVENT
DTSTART:20140619T080132Z
DTEND:20140619T090132Z
DTSTAMP:20140619T080132Z
ORGANIZER;CN=gonzo@work:mailto:gonzo@work
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
 FALSE;CN=gonzo@home;X-NUM-GUESTS=0:mailto:gonzo@home
CREATED:20140619T080132Z
DESCRIPTION:Description of flying to Sligo
X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//E
 N">'n<html>'n<body>'n<table border="1"><tr><td>'n<b>HTML</b> Description o
 f flying to Sligo'n</td></tr><tr><td>'n<ul><li>HTML has certain advantages
 </li></ul>'n</td></tr></table>'n</body>'n</html>
LAST-MODIFIED:20140619T080132Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Fly to Sligo
TRANSP:OPAQUE
UID:20140619T080132Z
END:VEVENT
END:VCALENDAR

我几乎读了所有关于它的东西,但是我真的不知道我的代码出了什么问题。它总是像附件一样显示,而不是像约会。

为什么我的icalcalendar不能被gmail识别?

你确定吗?运行你的代码,我得到两个基本错误。您需要提供一个from地址,而utf8行会导致问题。把它注释掉。这两个问题解决后,生成的邮件被gmail正确地解释为邀请。

日历,是从我最初问的这个问题复制过来的,很好。Gmail没有Outlook那么挑剔。

刚刚更改了我的SMTP凭据,一切正常…2天的工作…wtf gmail

<mailSettings>
  <!-- NOT WORKING
<smtp from="xxx@gmail.com">
    <network host="smtp.gmail.com" port="587" enableSsl="true" userName="xxx@gmail.com" password="yyy" />
  </smtp>-->
  <smtp from="info@something.else">
    <network host="mail.something.else" userName="info@something.else" password="yyy" />
  </smtp>
</mailSettings>
我代码:

using (var smtp = new SmtpClient())
{   
    var message = new MailMessage();
    message.To.Add(email);
    message.Subject = "Subject";
    // HTML
    message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, Encoding.UTF8, System.Net.Mime.MediaTypeNames.Text.Html));
    // VCARD
    System.Net.Mime.ContentType loCalendarType = new System.Net.Mime.ContentType("text/calendar; method=REQUEST");
    AlternateView icalView = AlternateView.CreateAlternateViewFromString(ical, loCalendarType);
    icalView.TransferEncoding = TransferEncoding.Base64;
    message.AlternateViews.Add(icalView);
    smtp.Send(message);
}