【发布时间】:2014-10-17 03:40:22
【问题描述】:
我有一个 .Net 4.5 应用程序,它发送带有附件的电子邮件。当电子邮件在桌面上打开时,它按预期工作,但在移动设备(本例中为 iPhone)上打开时,附件显示为内联 HTML 而不是附件。
但是,当我将同一封电子邮件从我的桌面转发到手机时,附件会正确显示在我的手机上,所以我几乎可以肯定它与我如何指定 mime 或内容类型、处置等有关。但是我看不出我做错了什么。
这是代码 - 请注意
att.ContentType = new System.Net.Mime.ContentType("multipart/mixed");
确实在 iPhone 上创建了一个附件,但它的类型 = mime-attachment 不会打开。
我很困惑,客户正在等待 - 非常感谢任何帮助!
private void SendNotice(string body, string attachment, string email, bool pdf = false)
{
MailMessage message = new MailMessage();
message.From = new MailAddress(ConfigurationManager.AppSettings["SMTP.SendFrom"]);
message.Subject = ConfigurationManager.AppSettings["MatchedNoticeSubject"];
message.To.Add(new MailAddress(email));
message.ReplyToList.Add(new MailAddress(ConfigurationManager.AppSettings["SMTP.ReplyTo"]));
message.Body = body;
message.IsBodyHtml = true;
Attachment att = Attachment.CreateAttachmentFromString(attachment, "SeniorInfo.html", System.Text.Encoding.ASCII, "text/html");
//specifying this creates an attachment of type "mime-attachment" that does not open
//att.ContentType = new System.Net.Mime.ContentType("multipart/mixed");
message.Attachments.Add(att);
SmtpClient server = new SmtpClient()
{
EnableSsl = (ConfigurationManager.AppSettings["SMTP.EnableSSL"].ToLower() == "true"),
Host = ConfigurationManager.AppSettings["SMTP.Server"],
Port = Convert.ToInt16(ConfigurationManager.AppSettings["SMTP.Port"]),
Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SMTP.Account"], ConfigurationManager.AppSettings["SMTP.Password"])
};
server.Send(message);
}
【问题讨论】:
标签: c# asp.net mobile email-attachments