Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having an HTML body when using the Gmail URL scheme in Swift 3

Tags:

swift

gmail

I'm looking to call the Gmail app with a preconfigured subject and the body contains HTML using the following:

let gmail = URL(string:"googlegmail:///co?subject=Subject&body=<body><H1>testing</H1></body>")
UIApplication.shared.openURL(gmail!)

This will crash the app, I then resort to:

var messageEncoded1 = "<body><H1>testing</H1></body>".addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)
let gmail = URL(string:"googlegmail:///co?subject=Subject&body="+messageEncoded1!")
UIApplication.shared.openURL(gmail!)

And this will create a URL and open Gmail, however, body of the email shows: <body><H1>testing</H1></body> and not the work testing like so:

testing

So the question is, is there a way to specify that the body holds HTML so that Gmail can render it as HTML?

like image 562
user481610 Avatar asked Jul 09 '17 20:07

user481610


1 Answers

No, for now, Gmail doesn't render it as HTML. Moreover, mailto standard RFC2368 itself doesn't obligate to render tags in body property:

The special hname "body" indicates that the associated hvalue is the body of the message. The "body" hname should contain the content for the first text/plain body part of the message. The mailto URL is primarily intended for generation of short text messages that are actually the content of automatic processing (such as "subscribe" messages for mailing lists), not general MIME bodies.

like image 115
Andrius Shiaulis Avatar answered Nov 03 '22 22:11

Andrius Shiaulis