Yes, you will be grandfathered in (but in a state that bans same-sex marriage you might experience some bureaucratic hassle and/or need to out yourself to prove the marriage is valid). The current national policy - not law, unfortunately - is to treat a marriage contract as legal if it was valid at the time it was signed, even if one of the parties subsequently changes gender. However, obviously, you WILL have to get married while retaining the male gender marker, and change it afterward.
I've been in the same boat, except that my state legalized SSM before it was an issue for me. The good news is that now that the feds also recognize SSM, there's no potential challenges in filing federal taxes, etc. In theory, you should also be OK at the state level, but again, keep a copy of your marriage license handy to prove that you were "male" at the time.
The majority of legal cases I have heard of that succeeded against a trans person were in situations where the person changed their gender marker and *then* married; nobody thus far seems to have run afoul of a marriage case in court where their birth gender was challenged.