There are some cases that you need to communicate with your users through email. Silvie comes with a helper function to send emails as easy as possible. This helper uses the nodemailer package to create the mail transporter and send emails from your application. All you need to do is to configure your SMTP server and email account credentials in the mail configuration file and import the helper function from silvie/utils/mail.

Send Mail#

The sendMail() function will take the email data, the receiver and the sender information. This function returns nothing, but you may get error messages in the console as if anything goes wrong.

The mail is the email address that you want to send the email from. This email address should be listed in the accounts section of mail configuration.

The aliasName will be shown as the name of the sender in the receiver inbox, set it to null if you don't want this to happen.

The to parameter is the receiver email address.

The htmlBody is optional, but you can send an HTML email body by passing a string with HTML contents to this parameter. It is recommended to send both text and HTML versions of an email in case a client does not support HTML content in email, or HTML content has been disabled for some reason.

import sendMail from 'silvie/utils/mail';
'Silvie JS',
'Contribution Notes',
'Hello, John.\nNow, you are one of our great contributors.\nThanks for contributing in the Silvie project.'

The above code will send an email from [email protected] with an alias name Silvie JS, to [email protected] with the provided subject and body.