- Node.js installed on your machine. You can download Node.js from the official website: https://nodejs.org
- Gmail account credentials (email address and password).
-
Clone the repository or download the script file.
-
Install the required dependencies by running the following command in the project directory:
npm install nodemailer dotenv
-
Create a
.env
file in the project directory and add the following lines, replacingEMAIL_ADDRESS
andEMAIL_PASSWORD
with your Gmail account credentials:EMAIL_ADDRESS=your-email@gmail.com EMAIL_PASSWORD=your-email-password
-
Place the PDF file you want to attach in the same directory as the script and name it
cv.pdf
.
-
Open the terminal or command prompt and navigate to the project directory.
-
Run the script using the following command:
node script.js
The script will send an email with the attached PDF file to the specified recipients.
- Modify the
tomail
variable in the script to include the email addresses you want to send the email to. - Update the
subject
andtext
variables in the script with your desired email subject and message.
The mailTransporter.sendMail()
function in the script uses Nodemailer to send the email. It configures the transporter with Gmail as the email service provider and uses the credentials provided in the .env
file for authentication.
The script reads the contents of the cv.pdf
file using the fs.readFile()
function, which should be present in the same directory as the script.
Make sure to handle any errors that may occur during the email sending process and provide appropriate error messages or notifications to the user.
That's it! You have successfully set up and run the Node.js email sender script. You should see the output indicating whether the email was sent successfully or if an error occurred.