#Upload file nodemailer

3 messages · Page 1 of 1 (latest)

paper jetty
#

I am using Astro to send a file that the client uploads to the company email
In the content part of the file, how do I pass a file buffer to it?

if(Astro.request.method === 'POST'){
    const formData = await Astro.request.formData()
    const file = formData.get('file')
    const { email } = await UserModel.profile({ id: user.id })

    const transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
            user: import.meta.env.EMAIL,
            pass: import.meta.env.EMAIL_PASSWORD,
        },
    });
    const mailOptions = {
        from: email,
        to: import.meta.env.EMAIL,
        subject: 'Payment ' + email,
        attachments: [
            {
                filename: file.name,
                content: ?????????
                contentType: file.type
            }
        ]
    };
    transporter.sendMail(mailOptions, (error) => {
        if (error) return error = 'Error al enviar el mensaje'
        return Astro.redirect('/')
    });
}

console.log(file) show:
File {
size: 262812,
type: 'application/pdf',
name: 'name.pdf',
lastModified: 1719289688034
}

radiant vesselBOT
#

Hi @paper jetty. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

I'm sorry, but the provided knowledge sources do not contain information on how to handle file uploads or use nodemailer with Astro. I recommend checking the official documentation or relevant resources for nodemailer and Astro to find the information you need.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: