SMS Message Formatting
Asked Answered
A

4

8

Could someone in the know tell me what kind of control I have on the formatting of SMS messages?

For example, bold text or carriage returns etc? Carriage return would be most important to me I suppose, is this possible to do and, if so, how?

Adela answered 27/6, 2011 at 14:30 Comment(0)
G
8

Formatting like bold text or italics, in general no - unless some particular SMS providers use a proprietary format for doing this (I'm not aware of any).

Standard SMSes are encoded using the GSM 03.38 7-bit alphabet which does include CR and LF (and FF) characters, but how these are rendered is up to the receiving end. Out of the two implementations I have to hand, both just ignore CR or LF (but one of them renders a line break if the message includes two consecutive spaces).

Geriatrician answered 27/6, 2011 at 15:8 Comment(2)
hmm ok I can live without the bold etc, but a line break would be VERY useful as what we are sending is a sort of receipt with balance before and after purchase... so line breaks would make it much more readable. Let me try and tinker with double spaces and see what that gives me.Adela
Fair enough, but try it with multiple different devices on the receiving end to make sure you get an overview of what they all do to it.Geriatrician
O
1

Actually, according to the GSM03.40 specifications, SMS can be formatted/decorated with bold, italic, colors, etc. using User Data Header (UDH) with a particular IE id (IEI) and IE data.

The proper IEI is 0x0A. This ID means "Text Formatting". From there, the payload describes the start offset and the end offset of the concerned portion of text and the style to apply to it.

I am not aware of any messaging app supporting this feature. However you can forge your own PDUs to embed such decorations.

Here is an example PDU (taken from here):

0041000B915121551532F40000631A0A031906200A032104100A032705040A032E05080A043807002B8ACD29A85D9ECFC3E7F21C340EBB41E3B79B1E4EBB41697A989D1EB340E2379BCC02B1C3F27399059AB7C36C3628EC2683C66FF65B5E2683E8653C1D

In any case, as stated in a previous answer, the interpretation of those UDH is left up to the receiving end. This means that even though your PDU embeds such features the application which renders the SMS may not render it as expected.

User Data Header - Wikipedia

Obmutescence answered 22/8, 2023 at 10:46 Comment(0)
P
0

I'm using twilio for a little project, and \n will produce a line break for me. Give it a shot!

body = "\U0001F6A8 Header with Emoji:\n---\nText after a divider because it is {}".format("awesome")

This is the extent to which I've been able to format the text. However, if whatever you're sending messages to support MMS, you might want to explore hacking your way to a formatted text message

Pyrethrum answered 10/1, 2020 at 23:10 Comment(0)
O
0

The format GSM 03.38 DO have CR/LF, not much more. You can see the whole map on:

https://en.wikipedia.org/wiki/GSM_03.38

Outride answered 4/3, 2021 at 17:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.