locked
Compose message sms not accepting semicolon RRS feed

  • Question

  • I've written a small piece of code in c# which takes an array of strings composed of 10 digit cell phone numbers uses the string.join method to create a single string delimited with semicolons and creates a list of recipients for a single sms message. for some reason when the string is sent to the compose message window the semicolons all disappear and it shows only a single very long number. when printing to the console the semicolons show up and all other symbols work. what would cause this and could i fix it?
    Monday, November 16, 2009 6:52 PM

Answers

  • No problem. Just create a proper method:

    private void OpenMessageForm(string numbers)
    {
         string format = "-service \"SMS\" -to \"{0}\" -body \"\"";
    
         Process pr = new Process();
         pr.StartInfo.FileName = @"\Windows\tmail.exe";
         pr.StartInfo.Arguments = string.Format(format, numbers);
         pr.Start();
    }

    It will replace {0} with the numbers separated with semicolon which You give as the argument.

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."

    I'm on MSDN just like MD House in the clinic. But I'm also a human which sometimes needs to see another doctor :)
    • Marked as answer by TheJacer Tuesday, November 17, 2009 9:33 PM
    Tuesday, November 17, 2009 3:08 PM

All replies

  • Which API do You use to send SMS? If You use "tmail.exe" "-service 'SMS' -to '123456;123456;123456' -body ''" it works, right?
    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."
    Monday, November 16, 2009 7:03 PM
  • I'm not sure, here's the code:
    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.WindowsMobile.Configuration;
    using Microsoft.WindowsMobile.DirectX;
    using Microsoft.WindowsMobile.Forms;
    using Microsoft.WindowsMobile.PocketOutlook;
    using Microsoft.WindowsMobile.Status;
    using Microsoft.WindowsMobile.Telephony;
    
    namespace SmartDeviceProject1
    {
        public partial class Form1 : Form
        {
            string[] numbers = new string[] { "5555555555", "5555555555", "5555555555" };
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Microsoft.WindowsMobile.Telephony.Phone myPhone = new Microsoft.WindowsMobile.Telephony.Phone();
                myPhone.Talk("5555555555");
            }
            
            private void Message_Click(object sender, EventArgs e)
            {
                           
                string Tonumbers = string.Join(";", numbers, 0, count);
                Console.WriteLine(Tonumbers);
                SmsMessage msg = new SmsMessage(Tonumbers,"");
                MessagingApplication.DisplayComposeForm(msg);
                
    
            }
    
            private void Email_Click(object sender, EventArgs e)
            {
                EmailMessage Emsg = new EmailMessage();
                Emsg.To.Add(new Recipient("")); //recipient omitted for posting
                Emsg.BodyText = "jjjj";
                Emsg.Send(""); //recipient omitted for code posting
    
            }
        }
    }
    Monday, November 16, 2009 7:56 PM
  • Yeeek! What a nasty piece of code :).
    Instead of SmsMessage and DisplayComposeForm clases use simple Process.Start, just like this:

    Process pr = new Process();
    pr.StartInfo.FileName = @"\Windows\tmail.exe";
    pr.StartInfo.Arguments = "-service \"SMS\" -to \"12345;12345\" -body \"\"";
    pr.Start();

    Process class is in System.Diagnostics.

    To get mail just replace SMS with EMAIL and add a proper address in -to.
    Have fun.

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."
    • Proposed as answer by Mal Loth Monday, November 16, 2009 9:04 PM
    Monday, November 16, 2009 9:04 PM
  • thanks for helping! but i need to know something else XD is this going to open the new sms form? because it's critical that the user be able to type their own body.
    Monday, November 16, 2009 9:05 PM
  • PS. You really don't need those:

    using Microsoft.WindowsMobile.Configuration;
    using Microsoft.WindowsMobile.DirectX;
    using Microsoft.WindowsMobile.Forms;
    using Microsoft.WindowsMobile.Status;

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."
    Monday, November 16, 2009 9:06 PM
  • okay, still having the issue.  The SmsMessage/DisplayComposeForm from above let me input a string variable as the recipient parameter ,but now using the process ,as suggested, I can't do that even.  The main issue here is that after the string variable is accepted, on the device ,in the recipient field the string is showing up as a single large number rather than several numbers delimited by semicolons.
    Tuesday, November 17, 2009 4:48 AM
  • I've checked that out BEFORE I posted You back and I know it works.
    You're just doing something wrong...

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."

    I'm on MSDN just like MD House in the clinic. But I'm also a human which sometimes needs to see another doctor :)
    Tuesday, November 17, 2009 6:57 AM
  • it needs to be able to take a variable...the numbers in the sample you posted are static. either im not understanding how to make a string array/string variable work in your sample or we've had a miscommunication.
    Tuesday, November 17, 2009 7:38 AM
  • No problem. Just create a proper method:

    private void OpenMessageForm(string numbers)
    {
         string format = "-service \"SMS\" -to \"{0}\" -body \"\"";
    
         Process pr = new Process();
         pr.StartInfo.FileName = @"\Windows\tmail.exe";
         pr.StartInfo.Arguments = string.Format(format, numbers);
         pr.Start();
    }

    It will replace {0} with the numbers separated with semicolon which You give as the argument.

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."

    I'm on MSDN just like MD House in the clinic. But I'm also a human which sometimes needs to see another doctor :)
    • Marked as answer by TheJacer Tuesday, November 17, 2009 9:33 PM
    Tuesday, November 17, 2009 3:08 PM
  • amazing! that worked perfect thank you very much XD
    Tuesday, November 17, 2009 9:33 PM