RPi - SMS to Mail with Raspberry Pi and ZTE MF823 Surfstick
(posted 2019.09.12, last updated 2023.12.11)

Goal

I want my Raspberry Pi Zero W to receive SMS on a spare SIM card / contract / number and send the contents to my mail account. Use case: some web services require your mobile number for registration but I do not like to give them my main number.

Update: Decided to try to use my OpenWRT instead of the Raspberry.

Update2: Fixed some issues with Modem switching from ttyUSB2 to ttyUSB3 and back.

Update3: Added ssmtp example for gmail.

Update4: Run in docker on Unraid server.

Steps

Setup USB-Surf-Stick ZTE MF823

The Surf-Stick is in network mode by default, in this mode no serial devices ttyUSB are offered (Other Surf-Sticks offer the modem directly by default). Sending/Receiving SMS could be handled using the web interface (as an API), but I would prefer to directly access the modem. The device can be put in modem mode and then gammu can be used to access it. Unfortunately, receiving SMS did not work at first, while sending was working well. Luckily, while experimenting I realized that changing the Preferred Message Storage solved that.

Setup SIM

Setup RPi Software

Alternatively: Setup OpenWRT Software

The issues with ttyUSB lead me back to a RPi configuration...

Update2: Fixed issue with ttyUSB*

The following did not help, still searching for a solution...

Had some issues where the modem switched from ttyUSB2 to ttyUSB3 and thereby gammu loosing connection

Someone had the same problem and I was able to use the solution posted there: (de) https://forum-raspberrypi.de/forum/thread/46635-warum-disconnected-gsm-modem-zte-mit-gammu-gesteuert-alle-2-stunden/

However, I had to adapt the solution, as there is no udev functionality for OpenWRT. Sadly, it is just a hack, as the PRODUCT/VENDOR code is the same for all ttyUSB0,1,2/3 that are created by the stick, so I just hope that either 2 or 3 is the one I want to access....

Alternatively: Run as docker container on unraid (Update 4)

- create folder in Unraid `..../appdata/sms2mail`
- put `gammurc`, `gammu-smsrc`, `ssmtp.conf`, and `smsin.sh` in folder.
- create `Dockerfile`
    ~~~
    FROM alpine:3.18

    #RUN apk add gammu
    RUN apk add gammu-smsd
    RUN apk add ssmtp

    COPY ./gammurc /etc/gammurc
    COPY ./gammu-smsrc /etc/gammu-smsdrc
    RUN mkdir -p /var/spool/gammu/inbox/
    RUN mkdir -p /var/spool/gammu/outbox/
    RUN mkdir -p /var/spool/gammu/sent/
    RUN mkdir -p /var/spool/gammu/error/
    COPY ./ssmtp.conf /etc/ssmtp/ssmtp.conf
    COPY ./smsin.sh /usr/local/bin/smsin.sh

    CMD gammu-smsd
    ~~~
- Build the image: `docker build . --tag sms2mail`
- optionally test image: `docker run --rm sms2mail` (stop)
- Install necessary plugin in Unraid UI: `USB Manager Serial Options addon` to get `/dev/ttyUSB<x>` devices.
- Use the Unraid UI to create container:
    Note: The container needs to run in priviledged mode to access the `/dev/ttyUSB<x>` devices
    - Go to "Add Container", enter Name "sms2mail", Repository "sms2mail", choose Network type (only requires outgoing connection for ssmtp), and switch "Privileged" to "On".

References

Raspberry Pi - Receive/Send SMS (gammu)

Switch ZTE Surfstick to Modem Mode (instead of Network Mode which offers no serial USB interface)

SMS / CPMS Info

ZTE AT Commands

ZTE use SMS using calls to the URL interface

ZTE + OpenWRT

Gammu + OpenWRT