0

我正在使用 iCal.Net 发送会议邀请。它在 Gmail 上运行良好,它向我展示了如下事件:

谷歌邀请

但是在 Outlook 上,它没有向我显示任何邀请,例如接受、暂定和拒绝选项。它向我展示了:

展望邀请函

它应该像这样显示:

Outlook 应有的样子

这是我的代码:

async Task<SendResponse> CreateCalendarEventAsync(
        CalendarNotificationModel calendarNotificationModel)
{
var attendees = calendarNotificationModel.Attendees.Select(x => new 
Ical.Net.DataTypes.Attendee()
{
    CommonName = x.AttendeeName,
    ParticipationStatus = "REQ-PARTICIPANT",
    Rsvp = true,
    Role = "REQ-PARTICIPANT",
    Value = new Uri($"mailto:{x.AttendeeEmail}")
}).ToList();

var e = new CalendarEvent
{
    Summary = calendarNotificationModel.Name,
    IsAllDay = true,
    
    Organizer = new Organizer()
    {
        CommonName = "HRMatrix",
        Value = new Uri("mailto:xyz@zxy.com")
    },
    Attendees = attendees,
    Status = "Confirmed",
    Sequence = 0,
    Start = new CalDateTime(calendarNotificationModel.StartDateTime),
    End = new CalDateTime(calendarNotificationModel.EndDateTime),
    Transparency = TransparencyType.Opaque,
    Location = calendarNotificationModel.Location,
    Description = calendarNotificationModel.Description
};

var calendar = new Calendar();
calendar.AddProperty("X-MS-OLK-FORCEINSPECTOROPEN", "TRUE");
calendar.AddProperty("METHOD", "REQUEST");

calendar.Events.Add(e);

var serializer = new CalendarSerializer();
var serializedCalendar = serializer.SerializeToString(calendar);

var bytesCalendar = Encoding.ASCII.GetBytes(serializedCalendar);
MemoryStream ms = new MemoryStream(bytesCalendar);
using (ms)
{
    ms.Position = 0;


    SmtpClient smtp = new SmtpClient
    {
        //The address of the SMTP server (I'll take mailbox 126 as an example, which can 
be set according to the specific mailbox you use)
        Host = "smtp.gmail.com",
        EnableSsl = true,
        Port = 587,
        DeliveryMethod = SmtpDeliveryMethod.Network,
        //Enter the user name and password of your sending SMTP server here
        Credentials  = new NetworkCredential("xyz@xyz", "sdfsdfsdfsdf")
    };
    //Set default sending information
    Email.DefaultSender = new SmtpSender(smtp);
    var email = Email
        //Sender
        .From("xyz@xyz")
        //Addressee
        .To("denis@org.com")
        //Message title
        .Subject("Interview")
        //Email content
        .Body("You are invited.");
    //Determine whether the transmission is successful according to the transmission 
 result

    var attachment = new FluentEmail.Core.Models.Attachment
    {
        Data = ms,
        ContentType = "text/calendar",
        Filename = "invite.ics",
    };
    email.Attach(attachment);

    var result = email.Send();
    //Or send it asynchronously
    //await email.SendAsync();

    return result;
}

}

这是我的 .ics 文件:

 BEGIN:VCALENDAR
 METHOD:Request
 PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
 VERSION:2.0
 X-MS-OLK-FORCEINSPECTOROPEN:TRUE
 BEGIN:VEVENT
 ATTENDEE;CN=XYZ;PARTSTAT=REQ-PARTICIPANT;RSVP=TRUE;ROLE=REQ-PARTICIPA
  NT:mailto:XYZ@hotmail.com
 DESCRIPTION:You are invited to give an interview
 DTEND:20220208T091006
 DTSTAMP:20220207T181006Z
 DTSTART:20220208T041006
 LOCATION:Pakistan
 ORGANIZER;CN=HRMatrix:mailto:xyz@gmail.com
 SEQUENCE:0
 STATUS:Confirmed
 SUMMARY:XYZ
 TRANSP:OPAQUE
 UID:b2ddc1ef-a2e4-4b0e-afa0-27d9689fbsdf
 END:VEVENT
 END:VCALENDAR

PS:如果我从 Gmail 客户端发送上述 .ics 文件,它可以工作,但不能从我的 SMTP 客户端工作。

4

1 回答 1

0

您好,您可以尝试在发送电子邮件或“mime”=>“文本/日历”时将附件字符集添加到“charset=UTF-8”;方法=请求;字符集=UTF-8'。

于 2022-02-10T05:47:32.970 回答