Flaviu's Blog - Read'n'Code

Paragraph Tags in HTML Email From iOS Makes PDF Attachment Not Show Up Outside of iOS

Here’s a standard way to send an HTML email with a PDF attachment from iOS:

1
2
3
4
5
6
7
8
9
10
11
12
// add the attachment
[mailComposer addAttachmentData:myData mimeType:@"application/pdf" fileName:@"comparison.pdf"];

// Fill out the email body text
NSString *emailBody = @" \
<p>Bla bla bla.</p>\
\
<p>See comparison attached.</p> \
";

[mailComposer setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:mailComposer animated:YES];

You will be happy when checking the result of this on your iOS device. However, when you check it in Gmail, it looks like this:

What? Why? I don’t know!! What I do know is that it works if you put br tags instead:

1
2
3
4
5
6
// Fill out the email body text
NSString *emailBody = @" \
Bla bla bla.<br /><br />\
\
See comparison attached. \
";

Now it looks as it should:

So, the lesson is: WTF?!

Comments

Fork Flaviu on GitHub