Search code examples
htmlasp.netiphoneoutlookemail-attachments

HTML attachment turns into plain text only for users on iPhones using Outlook app (non-default mail app)


We have a C# function that uses a streamwriter to create a HTML attachment from an ASPX file. that generates an email with a HTML attachment and sends to the user, this attachment displays fine on all android devices and iphone default mail app. However a user has discovered it turns into plain text when trying to open on iPhone with the Outlook app.

The attachment opens correctly on all desktop devices (Gmail, Outlook, etc)

It also works on iPhone default mail app and confirmed it only fails with the Outlook app.

We have also downloaded the file onto a PC then forwarded it back to an iPhone with Outlook, not changing the file at all and it worked fine.

//Only relevant code below

HttpContext.Current.Server.Execute(path, writer);
//path is filepath of aspx file
string msg = writer.ToString();

//filename is the html file
using (StreamWriter sw = new StreamWriter(filename,true)){
sw.write(msg);
sw.Dispose();
}

mail.Attachments.Add(new Attachment(filename));

Solution

  • So it turns out on further investigation that deeper in to the code I discovered we still had a line from prior version that forced it into plain text when it was being placed directly into the body. Strangely only the Outlook app on IPhone was actually affected by this.

    //OLD:
    contentType.MediaType = System.Net.Mime.MediaTypeNames.Text.Plain;
    
    //NEW:
    contentType.MediaType = System.Net.Mime.MediaTypeNames.Text.Html;