DefinitelyTyped / DefinitelyTyped/DefinitelyTyped

Nodemailer SMTP host throws error

Open
#67,197 15 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
51.4k
Forks
30.4k
Avg merge
3d 21h
Merged PRs (30d)
108

Description

SO im doing a project for myself and when creating a transporter the host throws the following error
No overload matches this call.
The last overload gave the following error.
Argument of type '{ host: string; port: number; service: string | undefined; auth: { user: string | undefined; password: string | undefined; }; }' is not assignable to parameter of type 'TransportOptions | Transport'.
Object literal may only specify known properties, and 'host' does not exist in type 'TransportOptions | Transport'.ts(2769)
index.d.ts(77, 17): The last overload is declared here.
(property) SMTPConnection.Options.host?: string | undefined

and my code is

 require("dotenv").config()
import nodemailer, {Transporter} from 'nodemailer'
import ejs from 'ejs'
import path from 'path'

interface EmailOptions {
    email:string,
    subject:string,
    template: string,
    data :{[key:string]:any}
}

const sendMail = async (options: EmailOptions) : Promise <void> => {
    const transporter : Transporter = nodemailer.createTransport({
        host : process.env.SMTP_HOST as string,
        port: parseInt(process.env.SMTP_PORT || '587') ,
        service: process.env.SMTP_SERVICE ,
        auth : {
            user: process.env.SMTP_EMAIL,
            password: process.env.SMTP_PASSWORD,
        }
    })
    const {email ,subject , template , data} = options

    //get the path to the email template
    const templatePath = path.join(__dirname, '../mails', template);

    //render the email template with ejs
    const html:string = await ejs.renderFile(templatePath,data)

    const mailOptions = {
        from : process.env.SMPT_MAIL,
        to: email,
        subject,
        template
    }
    await transporter.sendMail(mailOptions)
}

export default sendMail

code error

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the nodemailer.createTransport call and compare the supplied object with the Nodemailer TypeScript definitions referenced by the error. Verify the corrected transporter configuration by checking that the code type-checks and that transporter.sendMail can be called with the shown mail options.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.