Skip to content

feat: implement email notifications for contact form using nodemailer#30

Open
Adithyakp86 wants to merge 1 commit into
Ashrithhn:mainfrom
Adithyakp86:main
Open

feat: implement email notifications for contact form using nodemailer#30
Adithyakp86 wants to merge 1 commit into
Ashrithhn:mainfrom
Adithyakp86:main

Conversation

@Adithyakp86

Copy link
Copy Markdown

Description

This Pull Request implements email notifications for the contact form submissions using the existing nodemailer dependency.

Currently, submissions are saved only to a local contacts.json file. With this change, a stylized HTML and raw text email notification is also sent to the site administrator when a new submission occurs.

Proposed Changes

  • Nodemailer Integration: Imported nodemailer and configured an SMTP transporter utilizing environment variables (SMTP_HOST, SMTP_PORT, SMTP_SECURE, SMTP_USER, SMTP_PASS, CONTACT_SENDER, CONTACT_RECEIVER).
  • Winston Logger Fallback: Implemented a fallback logger warning when SMTP credentials are not configured, printing the formatted notification details directly to the Winston logger. This prevents server crashes/errors in environments without SMTP configuration.
  • Form Submission Hook: Updated the POST /contact endpoint to build the email payload and invoke the transporter asynchronously after successfully writing the entry to contacts.json.

Visual Design of the Email Notification

The notification email utilizes a clean, modern HTML layout featuring:

  • Highlighted header with site theme styling (#667eea).
  • Organized contact details (Name, Email link, Subject).
  • Formatted message block with a blockquote indicator for enhanced readability.

Verification & Testing

Manual Verification

  1. Without SMTP Configured (Fallback):

    • Started the server locally (npm start).
    • Submitted a mock contact form submission.
    • Verified that the server outputted the fallback message:

      [warn]: SMTP credentials not configured. Email notifications will be logged instead of sent.

    • Verified the Winston logs printed the correct mail options payload:
      {
        "from": "no-reply@nexuscore.io",
        "to": "admin@nexuscore.io",
        "subject": "New Contact Form Submission: collaboration",
        "text": "Name: Jane Doe\nEmail: jane@example.com...",
        "html": "..."
      }
    • Confirmed the submission was successfully written to contacts.json.
  2. Syntax Check:

    • Ran node -c server.js to ensure zero compilation or syntax errors are introduced.

Checklist

  • My code follows the code style of this project.
  • I have verified the changes locally.
  • All existing server logic and file writes operate as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant