Moodle has two ways of mailing a user:
email_to_user(), which is used for account-related notifications which should always result in an email (e.g. email address validation, password resets).
message_emailplugin, which may send emails based on the user's notification preferences.
Both of these eventually result in Moodle sending the message to the MTA over SMTP.