0

My code working perfectly if the SMS messages to be sent has less than 70 characters.

I want to send messages with between 70 to 200 characters per message.

using GsmComm.GsmCommunication;
using GsmComm.PduConverter;
using GsmComm.Server;
using GsmComm.PduConverter.SmartMessaging;

namespace SMSSender
{
public partial class Form1 : Form
{

public Form1()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {

        try
        {
            string msg = " کو  ہم نے";
            GsmCommMain comm = new GsmCommMain(4, 19200, 500);
            comm.Open();           
            SmsSubmitPdu pdu;
            pdu = new SmsSubmitPdu(msg, "03319310077", DataCodingScheme.NoClass_16Bit);              
            comm.SendMessage(pdu);
        }
            catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
}

}

srborlongan
  • 4,460
  • 4
  • 26
  • 33
Fahad Khan
  • 22
  • 2
  • You are limited to 67 character. See : https://www.twilio.com/docs/glossary/what-sms-character-limit – jdweng Jan 11 '20 at 20:36
  • @jdweng The OP isn't using Twilio, they're using a GSM modem directly. In which case it depends on the functionality offered by the modem. – Dai Jan 12 '20 at 02:04
  • It is still the standard for SMS. Doesn't matter the carrier. – jdweng Jan 12 '20 at 03:44

1 Answers1

0

If you take a look at the source here for the SmsPdu class here, you can see that there's an explicit limit of 70 Unicode characters, which would explain the issue you are encountering:

public abstract class SmsPdu : ITimestamp
{
        // Omitted for brevity 
    
        /// <summary>
        /// Gets the maximum Unicode message text length in characters.
        /// </summary>
        public const int MaxUnicodeTextLength = 70;

        // Omitted for brevity
}

Possible Workaround

A possible workaround might involve breaking a single message into multiple batches of less than 70 characters and sending multiple to the same destination:

public static IEnumerable<string> BatchMessage(string message, int batchSize = 70)
{
        if (string.IsNullOrEmpty(message))
        {
            // Message is null or empty, handle accordingly
        }
        
        if (batchSize < message.Length)
        {
            // Batch is smaller than message, handle accordingly    
        }
        
        for (var i = 0; i < message.Length; i += batchSize)
        {
            yield return message.Substring(i, Math.Min(batchSize, message.Length - i));
        }
}

And then simply call that prior to sending your message and send the batches individually:

// Open your connection
GsmCommMain comm = new GsmCommMain(4, 19200, 500);
comm.Open();  
            
// Store your destination
var destination = "03319310077";
            
// Batch your message into one or more
var messages = BatchMessage(" کو  ہم نے");
foreach (var message in messages)
{
    // Send each one
    var sms = new SmsSubmitPdu(message, destination, DataCodingScheme.NoClass_16Bit);
    comm.SendMessage(sms);
}
Community
  • 1
  • 1
Rion Williams
  • 74,820
  • 37
  • 200
  • 327
  • I am doing exactly But I am getting a message in a parts for example, 70 letters in one message and 70 in other, I want all in one message. please edit my code if you got my point. – Fahad Khan Jan 12 '20 at 18:11
  • This ins't possible without explicitly adjusting the source on it's own and recompiling it yourself (you can use the link provided earlier in my post). Just adjust that constant value from 70 characters to Int.MaxValue or something similar. I suspect that this was implemented for a specific reason and it may just be a limitation of how these messages are sent. – Rion Williams Jan 12 '20 at 19:28
  • i have got the solution and now it's working perfectly. https://stackoverflow.com/questions/51136293/cant-send-more-than-160-characters-sms-c-sharp-using-gsm-modem?rq=1 – Fahad Khan Jan 15 '20 at 10:07