【发布时间】:2016-08-31 13:01:11
【问题描述】:
我正在尝试将 iCal 格式的日历邀请添加到通过 MailGun API 发送的电子邮件中。这是我到目前为止所拥有的:
var request = new RestRequest();
request.AddParameter("domain", this.domain, ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter("from", contactDetails.SenderAddress);
request.AddParameter("to", contactDetails.RecipientAddress);
request.AddParameter("subject", message.Subject);
request.AddParameter("text", message.TextBody);
request.AddParameter("html", message.HtmlBody);
if (!string.IsNullOrWhiteSpace(message.IcalAttachment))
{
request.AddFileBytes("attachment",
Encoding.UTF8.GetBytes(message.IcalAttachment),
"invite.ics",
"text/calendar");
}
request.Method = Method.POST;
return request;
这会导致日历作为附件包含在电子邮件中,而不是电子邮件的替代视图。附件在 gmail 中运行良好,但在 Outlook 中显示为附件文件,您必须先单击该附件,然后同意将日历添加到 Outlook 日历。是否有其他方法可以使用 REST api 以便正确发送日历邀请,作为替代电子邮件视图?
明确地说,这就是我使用 .Net SmtpClient 发送日历邀请的方式:
var contentType = new ContentType("text/calendar");
if (contentType.Parameters != null)
{
contentType.Parameters.Add("method", "REQUEST");
contentType.CharSet = "UTF-8";
}
// this is the same way you add a html view to the message
request.AlternateViews.Add(
AlternateView.CreateAlternateViewFromString(
message.IcalAttachment,
contentType));
【问题讨论】:
-
我遇到了同样的问题。 Mailgun 将 ics 作为附件发送,它仅适用于 SMTP。但我不能使用 SMTP,因为它将电子邮件发送到垃圾邮件。请帮忙。