E-mail is probably the simplest and most common way of notifying users about information in Moodle. Forum subscriptions, activity submissions, and course welcome messages, all use this method.
In Moodle, there are also various reasons why specific users should not receive e-mails. Users can specify in their profile that they do not want to receive e-mails. Moodle may have determined that a user's e-mail address is bouncing. Or, a user may have their account suspended or terminated. In these cases, you want to make sure you are obeying the settings and not send e-mail to those users.
Also, users may want to receive text-only e-mail or prefer to receive HTML e-mail (as seen in the following screenshot). You would want to make sure you sent the message in the appropriate format:
Fortunately, Moodle makes this easy for you. You just need to use its email_to_user
API function, and let the function worry about whether the e-mail should be sent and in what format it should be sent...