Let me preface by saying this is how I did it and haven’t seen or found another way. You may come up with another idea, part, or process that is cheaper or better.
As mentioned you need electronics harvested from an older mirror. Part #51167401098 contains heat, dim, auto fold, tilt, memory - pretty much every feature. There may be others as well. It’s an older one so you may be able to find in a junk yard, eBay, and they still sell new. I was not able to find just the electronics needed (though some BMW models do sell it separately, so there may be a tiny chance it exists.)
The basic process is to remove the existing mirror glass, cap, and housing from the vehicle. Transplant the electronics by unclipping the flat controller (see picture for the part I am talking about.) It has 4 sets of wires (input, heat, dim, fold) and a hidden press fit connector. Once you pry the retaining clips it more or less comes out easy. Then you press in the donor controller and solder the wires I mention next.
The only snag was, I couldn’t figure out how to safely remove the white+yellow wire for the fold motor. Everything seems water tight and hard to take apart. I ended up snipping and soldering that connection, the rest remain intact and cleanly work.
Finally you need dimming glass. I installed on day one as part of “euro mirror” kit and don’t recall exactly which part #. It is apparent by the perimeter etching.
View attachment 19991