Downloading MMS Attachments from incoming messages

  • 20 October 2023
  • 1 reply

I have a project where we have a number that customers will send images too. I'm writing a program thats supposed to download those images and forward them to a company email. I have a webhook setup that works fine for incoming message events. I'm writing this all in java and need to figure out how to download the image from the message using either the URI or any other method. Thanks.

1 reply

I don't have the code for parsing and downloading attachments from the notification payload. But you can modify this code snippet to work with the notification payload.

public void read_message_store_sms() throws RestException, IOException{
        ListMessagesParameters parameters = new ListMessagesParameters();
        parameters.messageType = new String[] {"SMS"};
        parameters.dateFrom = "2023-05-01T00:00:00.222Z";
        var response = restClient.restapi().account().extension().messageStore().list(parameters);
        for (GetMessageInfoResponse record : response.records)
            if (record.attachments != null)
                for (var attachment : record.attachments)
                    var fileName = "./src/test/resources/" + record.attachments[0].id + "_mms";
                    if (attachment.type.equals("MmsAttachment"))
                        if (attachment.contentType.equals("image/png"))
                            fileName += ".png";
                        else if (attachment.contentType.equals("image/jpeg"))
                            fileName += ".jpg";
                            fileName += ".xxx"; 
                    var res = restClient.restapi().account().extension().messageStore(;
                    Path path = Paths.get(fileName);
                    Files.write(path, res);

All you need is to parse the payload, check the "attachments" then use the code above to download it.

Note: This code uses the RingCentral Java SDK.