This addon might not do what you want .. but has some elements that may help you extract the code to help you do what you want..
https://www.wowinterface.com/downloa...lversions.html
And this one might even have what you want amongst its bells and whistles .. albeit a guild welcome message rather than a whisper.
https://www.wowinterface.com/downloa...toGratzer.html