Which sentence uses the comma correctly?
A.
Mr. Smith the mayor, was not re-elected.
B.
Mr. Smith, the mayor, was not re-elected.