Send SMS with C++

ISendService2 interface

Contains functions and methods that enable you to send SMS Messages.

Implemented by the SendService2 class

EsendexLib::SendService2 spSendService;

spSendService.CreateInstance(uuidof(EsendexLib::SendService2)); 

Initialise method

Initialise the class with your Esendex credentials. You must call this method before you call any other on the interface. C++ syntax

Initialise(_bstr_t Username, _bstr_t Password, _bstr_t Account, _variant_t IsServerSide); 

Parameters

  • Username Your Esendex username.
  • Password Your Esendex password.
  • Account Your Esendex Account Reference.
  • IsServerSide (optional) True if the component is running within an ASP page; false or otherwise. The default is false.

SendMessage function

Sends an SMS Message to the specified Recipient using the default Alias and validity period.

_bstr_t SendMessage(_bstr_t Recipient, _bstr_t Body, MESSAGE_TYPE Type); 

Parameters

  • Recipient The mobile number to which the Message will be sent.
  • Body The content of the Message. The maximum length depends on the value you specify for Type. It can be up to 160 characters for Text, 140 characters for Binary and SmartMessaging or 70 characters for Unicode.
  • Type The type of Message: Text, Binary, SmartMessage or Unicode.
  • Return Value: The ID of the Message assigned by Esendex.

SendMessageFull function

Sends an SMS Message to the specified Recipient.

_bstr_t SendMessageFull(_bstr_t Originator, _bstr_t Recipient, _bstr_t Body, MESSAGE_TYPE Type, long ValidityPeriod); 

Parameters

  • Originator The Alias the Message should appear to come from. This can be another mobile number or up to 11 alpha-numeric characters. With Evaluation Accounts, this parameter must be set to the Virtual Mobile Number assigned by Esendex. With Premium Rate Accounts, this parameter must be set to the Account short code.
  • Recipient The mobile number to which the Message will be sent.
  • Body The content of the Message. The maximum length depends on the value you specify for Type. It can be up to 160 characters for Text, 140 characters for Binary and SmartMessaging or 70 characters for Unicode.
  • Type The type of Message: Text, Binary, SmartMessage or Unicode.
  • ValidityPeriod The time, in hours, for which the Message is valid. You can specify zero to use the default validity period.
  • Return Value: The Id of the Message assigned by Esendex.

SendMessageMultipleRecipients function

Sends an SMS Message to the specified Recipients using the default Alias and validity period.

IStringCollection2Ptr SendMessageMultipleRecipients (_variant_t Recipients, _bstr_t Body, MESSAGE_TYPE Type); 

Parameters

  • Recipients A comma-separated list of mobile numbers to which the Message will be sent.
  • Body The content of the Message. The maximum length depends on the value you specify for Type. It can be up to 160 characters for Text, 140 characters for Binary and SmartMessaging or 70 characters for Unicode.
  • Type The type of Message: Text, Binary, SmartMessage or Unicode.
  • ValidityPeriod The time, in hours, for which the Message is valid. You can specify zero to use the default validity period.

Return Value: An collection containing the Ids of the Messages assigned by Esendex.

SendMessageMultipleRecipientsFull function

Sends an SMS Message to the specified recipient.

IStringCollection2Ptr SendMessageMultipleRecipientsFull (_bstr_t Originator, _variant_t Recipients, _bstr_t Body, MESSAGE_TYPE Type, long ValidityPeriod); 

Parameters

  • Originator The Alias the Message should appear to come from. This can be another mobile number or up to 11 alpha-numeric characters. With Evaluation Accounts, this parameter must be set to the Virtual Mobile Number assigned by Esendex. With Premium Rate Accounts, this parameter must be set to the Account short code.
  • Recipients A comma-separated list of mobile numbers to which the Message will be sent.
  • Body The content of the Message. The maximum length depends on the value you specify for Type. It can be up to 160 characters for Text, 140 characters for Binary and SmartMessaging or 70 characters for Unicode.
  • Type The type of Message: Text, Binary, SmartMessage or Unicode.
  • ValidityPeriod The time, in hours, for which the Message is valid. You can specify zero to use the default validity period.

Return Value: An collection containing the Ids of the Messages assigned by Esendex.

GetMessageStatus function

Returns the status of a previously submitted Message.

MESSAGE_STATUS GetMessageStatus(_bstr_t MessageID);

Parameters

  • Message The Id of the Message whose status you want to query.

Return Value: The Message status. This can be Queued, Sent, Delivered or Failed.

SendMessage Sample

Once you have imported the COM component You can send a Message as follows:

EsendexLib::SendService2 spSendService;

spSendService.CreateInstance(uuidof(EsendexLib::SendService2));

spSendService->Initialise("MyUserName", "MyPassword", "MyAccount");

spSendService->SendMessage("441234567890", "Hello”, EsendexLib::MESSAGE_TYPE_TEXT); 

MFC users should remember to call AfxOleInit() in the application’s InitInstance() method, whilst non-MFC users should initialize COM with a call to CoInitialize().

Send Message Console sample

The SendMessage folder in the SDK contains a simple console application (SendMessage.sln) that demonstrates how to send an SMS Message.

Application flow is as follows:

  • SendMessage.cpp contains a line to import the Esendex type library.
  • Constants are defined for the username, password, Account and Recipient. You will need to change these to contain your own details.
  • The main method Intialises the COM subsystem.
  • The SendWorker() method is called to Send the SMS Message.
  • The Esendex SendService2 component is created.
  • The user’s Account information is passed to the SendService2 component.
  • The SendMessage method is used to despatch the SMS Message.