Send SMS Programmatically

Please provide the following:

  1. SDK Version: 2.11.2
  2. Platforms(ios/android/both): both

Hi All, I hope this is the right place to raise my query–if not I’m happy to move this elsewhere.

I’m looking to periodically send reminder text messages as a background process. I tried SMS.sendSMSAsync(), which is awesome, but this pulls up the default SMS service on the host and requires the user to submit the send button. That’s not fatal but it’d be nicer to do this in the background.

I have started exploring sending SMS programmatically from a simple server-side Python, ala:

import smtplib
import email.mime.multipart

sender = 'douglas.duhaime.messenger@gmail.com'

# Establish a secure session with gmail's outgoing SMTP server using your gmail account
server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(sender, YOUR_PASSWORD_GOES_HERE)

msg = '\r\n'.join([
  'MIME-Version: 1.0',
  #'Date: Fri, 22 Feb 2019 11:29:27 -0500',
  #'Message-ID: 12345678',
  'Subject: cartes', # shows up in bold at top of message
  'From: Douglas Duhaime <douglas.duhaime.messenger@gmail.com>',
  'To: MY_PHONE_NUMBER@tmomail.net',
  'Content-Type: multipart/alternative; boundary="0000000000003c664305827e1862"',
  '',
  '--0000000000003c664305827e1862',
  'Content-Type: text/plain; charset="UTF-8"',
  '',
  'message from dd',
  '',
  '--0000000000003c664305827e1862',
])

# sendmail(from, to, msg)
server.sendmail('douglas.duhaime.messenger@gmail.com', 'MY_PHONE_NUMBER@tmomail.net', msg)

That indeed sends me a text message, but requires me to know the service provider of the recipient, and shows the sender as douglas.duhaime.messenger@gmail.com, while I’d like the user’s phone to show up as the sender.

Is there a straightforward way to send a message programmatically with expo or related server-side code? I’d be grateful for any advice others can offer on this question.

Hi

FYI 2.11.2 looks like the version of the Expo app rather than the SDK version. The app supports a range of SDK versions. The SDK version would be in your app.json file. If you’ve just created a new app with an up to date version of expo-cli then it would be version 34.

The Python code you posted is basically just sending an email to some service that presumably sends the sms on your behalf. So whether you can change the sender etc. would depend on that service. This has nothing to do with Expo.

If that service doesn’t work for you maybe there’s another SMS provider that will work for you.

e.g.:

https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html

1 Like