1

My code:

<a href="mailto:anything@any.com?subject=This%20is%20Subject&body=Hello%0D%0A%0D%0Aworld..">
   click here to mail me
</a>

Expected output:

enter image description here

What i am getting as output now:

enter image description here

I tried using %0D%0A but it doesn't work. Also i tried few java script methods from here But those don't seems to work.

The app i used to check mailto: output is default Gmail App from my android device.

EDIT [SOLUTION]

Just using <br> tag works fine with third party applications like gmail for android.

Manoj
  • 41
  • 5

3 Answers3

4

Update 09 Sep 2020 This has been changed again in a recent Gmail release - e.g. version 2020.08.09.327326543.Release - \r\n for line breaks when using mailto: now works again and <br> does not.

I can only assume it was a regression bug rather than an intentional change in the Gmail app which has now been fixed.

Original answer:

I've seen an issue arise recently in my Android apps which have been using encoded \r\n for line breaks when using mailto: to open Gmail as the default email client. While this previously worked fine, now the line break is appearing as a space.

Upon doing some testing, it appears that the behaviour of the Gmail app has changed in a recent update.

I created a test page which contains two links, one using encoded \r\n and one using <br> for a line break in the body:

mailto:anything@any.com?body=Hello%0D%0Aworld
mailto:anything@any.com?body=Hello<br>world

In an Android Emulator running Android 10/API 29 with Gmail app version of 2019.05.12.250526289.release:

pixel3-gmail

The \r\n link works correctly:

![pixel3-rn

But the <br> link does not:

![pixel3-br

In an Android Emulator running Android 11 Beta/API 30 with Gmail app version of 2020.04.29.309137422.release:

pixel3a-gmail

The <br> link works correctly:

pixel3a-br

But the \r\n link does not:

pixel3a-rn

DaveAlden
  • 30,083
  • 11
  • 93
  • 155
3

%0D%0A are the carry return and line feed characters, use %20 for space as you do in the subject:

<a href="mailto:anything@any.com?subject=This%20is%20Subject&body=Hello%20world..">
   click here to mail me
</a>

And if you want a line break use %0D%0A as in:

<a href="mailto:anything@any.com?subject=This%20is%20Subject&body=Hello%0D%0Aworld..">
   click here to mail me
</a>

You can check what this values mean in a ascii table if you check the hexadecimal value you see what A, D, E and 20 are equal to.

jeprubio
  • 17,312
  • 5
  • 45
  • 56
  • i need a line break like u said exactly in first line, i need return.. Not space. I know %20 used for space and found %0D%0A used for line break. But, when am using it, it doesn't work. Kindly go through my question or expexted output or atleast my title itself says i need line break. – Manoj Apr 13 '20 at 11:00
  • Kindly check out my post last quotes, i was trying it in gmail app Android. Is that u too tried with the same and works ? i click on website href mailto: it redirect to gmail app on mobile and doesn't give line break as i shown in expected output its a gmail app of android. (which most of the users used to mail me from my site) and i think u checked in pc and yes works for me to in pc browsers. – Manoj Apr 13 '20 at 11:13
  • Yo are right, it was quicker to test on pc. Only in gmail in android fails. I've found a couple of posts asking for the same https://stackoverflow.com/questions/40276780/how-to-make-line-break-work-in-inbox-by-gmail-using-mailto and https://stackoverflow.com/questions/60065386/is-it-possible-to-add-a-new-line-in-mailto-url with the same problem and without any answer, `%0D%0A` should be the way but this seems to be a gmail bug in Android as this works on iOS gmail. – jeprubio Apr 13 '20 at 11:27
  • Thanks a lot for sharing these post links it works. I saw a comment in those posts says simply use `
    ` works with third party apps like gmail. I tried and works.
    – Manoj Apr 13 '20 at 11:35
  • 1
    I'm glad you could solve your problem. You could add your own answer to your question and after a couple of days you will be able to mark it as correct, it might help others as well. – jeprubio Apr 13 '20 at 11:37
1

Just using <br> tag, works fine with third party applications like gmail for android.

Fixed code,

<a href="mailto:anything@any.com?subject=This%20is%20Subject&body=Hello<br><br>world..">
   click here to mail me
</a>
Manoj
  • 41
  • 5