How to decide the mail format(Html/Plain text) in code when sending

I want to design a mail template which make it possible for user sending a mail to two types of recipient, one will receive html-format mail, the other will only receive plain text one.

So how can i solve this problem in code way,

not configuration way.

Thanks