Back up all data.
Quit Messages if it’s running. Force quit if necessary. After each of the following steps, restart the computer and test. If the problem isn't resolved, quit again and go on to the next step.
Step 1
If you sync Contacts with a service such as iCloud or Google, disable the synchronization in the iCloud or Internet Accounts pane of System Preferences. When prompted to confirm, choose to delete the contacts from the Mac. They'll still be on the servers and on your other devices. Leave the preference pane open.
If Messages works now, re-enable Contacts synchronization, wait for the network contacts to reappear, and see what happens.
Step 2
Make sure you know the ID and password you use with iMessage.
Launch the Keychain Access application in any of the following ways:
☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
☞ Open LaunchPad and start typing the name.
Select the login keychain from the list on the left side of the Keychain Access window. If your default keychain has a different name, select that.
If the lock icon in the top left corner of the window shows that the keychain is locked, click to unlock it. You'll be prompted for the keychain password, which is the same as your login password, unless you've changed it.
From the menu bar, select
Keychain Access ▹ Keychain First Aid
from the menu bar and repair the keychain.
From the Category list in the lower left corner of the window, select
My Certificates
Look carefully at the list of certificates in the right side of the window. If any of them is marked with a red "X" as expired or invalid, delete it. Also delete all items with "iMessage" or "com.apple.idms" in the name, whether valid or not.
Now select
Keychain Access ▹ Preferences... ▹ Certificates
There are three menus in the window. Change the selection in the top two to Best attempt, and in the bottom one to CRL.
Next, select
Passwords
in the Category list. Enter "ids" (without the quotes) in the search box in the toolbar of the window. Delete all items of type "application password" that have a name beginning in any of the following ways:
ids:
IDS:
com.apple.ids:
Quit Keychain Access. Log out and log back in.
Step 3
Hold down the option key and select
Go ▹ Library
from the Finder menu bar. Move the following items from the Library folder to the Trash (some may not exist):
Containers/com.apple.corerecents.recentsd
Caches/com.apple.Messages
Caches/com.apple.imfoundation.IMRemoteURLConnectionAgent
Containers/com.apple.iChat/Data/Library/Caches
Containers/com.apple.soagent
IdentityServices
Leave the Library folder open.
Step 4
Go back to the Finder and move the following item from the open Library folder to the Desktop:
Messages
Note: you are not moving the Messages application. You’re moving a folder named “Messages.”
If Messages now works, delete the Messages folder on the Desktop. Otherwise, quit Messages again. Put back the folder you moved, overwriting the newer one that may have been created in its place.
Step 5
In the Preferences subfolder, there may be several files having names that begin with any of the following strings:
com.apple.iChat
com.apple.ids
com.apple.imdsmsrecordstore
com.apple.imessage
com.apple.imservice
Move them all to the Desktop. There may also be a file with the name "com.apple.imagent.plist". Move that to the Trash.
Also in the Preferences folder, there's a subfolder named "ByHost". Open it and do the same thing.
Log out and log back in. Test again. This time Messages should perform normally, but your settings will be lost. You may be able to put back some of the files you moved to the Desktop in this step. Relaunch and test after each one. Eventually you should find one or more that causes Messages to malfunction. Delete those files and recreate whatever settings they contained.
If the issue is still not resolved, quit Messages again and put all the items you moved to the Desktop back where they were. You don’t need to replace the items you moved to the Trash. Stop here and post your results.
If you later decide that you don’t like the results of Steps 3 and 4, you can undo them completely by quitting Messages and restoring the items you deleted in those steps from your backup.