[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Help](/c/help/9)

# Receiving Formdata on gmail on localhost but not via website

73 views · 0 likes · 2 posts


Abdulmohiz01 (@abdulmohiz01) · 2024-08-04

Hi,
I'm using nodemailer to send form data to my gmail. When I submit it via localhost, I receive it on my gmail but when i host it, the response is 200 but I dont receive any on my gmail app. Im using my one email to send to another email which's also mine. 
Can someone please tell what's the issue and how to solve it? I'm using next.js 14.
For reference, here's the link to the website: www.nexusencryption.com and here's my code: 
"
import nodemailer from 'nodemailer'
import { NextResponse } from 'next/server';

export async function POST(request) {
  try {
    const data = await request.json();
    // console.log(data);
    const { name, email, subject, message } = data;
    const transporter = nodemailer.createTransport({
      service: 'gmail',
      auth: {
        user: process.env.emailFrom,
        pass: process.env.pass,
      },
    });
    const mailOptions = {
      from: process.env.emailFrom,
      to: process.env.emailTo,
      subject: `${subject}`,
      text: `Name: ${name} \nEmail: ${email}\n\nMessage: ${message}`,
    };
    transporter.sendMail(mailOptions, (error, info) => {
      if (error) {
        console.log(error);
        res.status(500).send('Internal Server Error');
      }
      else {
        console.log('Email Sent: ' + info.response);
      }
    });


    return NextResponse.json({ message: 'Data received successfully' }, { status: 200 });
  } catch (error) {
    console.error(error);
    return NextResponse.json({ message: 'Error processing request' }, { status: 500 });
  }
}
 
export async function GET(request) { 
  return NextResponse.json({ message: 'This is a GET request' }, { status: 200 });
}
"


Pauline P. Narvas (@pawlean) · 2024-08-05

Hi, @abdulmohiz01!

Have you seen our guide https://vercel.com/guides/sending-emails-from-an-application-on-vercel? From the guide:

> You can also use libraries like [nodemailer](https://www.npmjs.com/package/nodemailer). When doing so, we recommend using an external `host` value provided by a third-party provider, rather than defaulting to the outbound SMTP connection of the Serverless Function.

Might be useful!