Sending email on a specific time programatically

I want to schedule email to be sent on a specific time and date using a doctype, how is this possible through code? can we create cronjobs through code?