Yes. Just cut out a rectangular hole the size and deepness for your electrical box*, then mortar the electrical box into the hole.
New construction, use a half brick or cut a brick to the size you need. Mortar in the electrical box and wire along with the bricks.
*As to cutting the rectangular hole, I would draw the outline of the electrical box on the wall. Then using a level, I would draw lines about 1/2 inch further out from the size of the electrical box. This would be so you could "squish" mortar in around the sides of the electrical box to hold it in place.
Then I would use a "masonry blade" on a circular saw to make the first cuts. This would give you smooth lines on the edges. Carefully and just barely saw into the wall so the cuts do not go beyond the rectangular lines drawn on the wall. These cuts would not go very deep of course.
Then with masonry drill bits and a hammer drill, I would drill a bunch of holes on the inside of the lines drawn. And I would mark the deepness to drill on the drill bit by holding up the electrical box to the bit, then placing masking tape on the bit so the hole would be about 3/4 inch deeper than the box. This would allow room in the back for a romex clamp, the wire, and
mortar. (And drill no deeper than the tape on the bit.)
Then I would use a straight blade on the hammer drill to chip out the rest of the rectangular hole. Or a cold chisel. The more holes you drill, the easier it will be to chip the pieces out.
Then drill a hole all the way through for the wire or whatever - run the wire.
Then install romex clamp. Leave about 8 inches of wire going out the electrical box. Then mortar it into place.
(Someone else may have a better way to do this, so stay tuned...)
Circular saw masonry blade...