Hosting de GoDaddy Node.js Ayuda

Send email using Node.js Hosting

Node.js Hosting comes with an email gateway you can use to send transactional emails, contact form notifications, sign-up confirmations, password resets, and receipts, straight from your code. You don’t need an SMTP server, username, password, or third-party email service. Your code sends an HTTP request to the gateway, and the gateway handles delivery for you.

Note: This article covers an advanced topic for informational purposes only. If you require support for your email code, you'll need to contact your developer.

Select a link to see its answer:

How does Node.js Hosting email work?

Your app sends a POST request with a JSON body to the endpoint, http://127.0.0.1:2525/api/email/send. The gateway will check the message, build the email, and deliver it. The gateway can only be reached from your app’s code. It can’t be reached from the internet, from your browser, or from your own computer.

Volver arriba

How can I send email?

You'll need to create a file on your server and call it. Below is an example you can use.

Note: Be sure to update the example code to your app or site
const response = await fetch("http://127.0.0.1:2525/api/email/send", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    to: ["you@example.com"],
    subject: "Hello from my Node.js app",
    text: "It works! This email was sent from my app on GoDaddy Node.js Hosting.",
  }),
});

const result = await response.json();
console.log(result); // { success: true, messageId: "..." }

Volver arriba

Email code requirements and options

Below are email code requirements and some common optional fields you can include.

CampoObligatorioDescripción
toSíRecipient addresses. At least one is required.
subjectSíThe subject line
text or htmlAt least one (both are ok)Text or HTML body
ccNoCarbon-copy recipients
bccNoBlind-copy recipients
replyToNoWhere replies go (for example, the visitor that filled out a contact form)
attachmentsNoFiles to attach
contentTypeNoHow to interpret attached files
fromNoSender address. A default user will be used if left blank. For the best reliability, enter an email address that uses the same domain as your Node.js Hosting and can receive messages (for example, jane@coolexample.com).

Volver arriba

How do attachments work?

When sending email with attachments, there are requirements to keep mind.

CampoObligatorioDescripción
filenameSíThe file name the recipient sees (for example, invoice.pdf)
contentSíThe file’s contents.
contentTypeNoThe MIME type.

When sending email with attachments, there are requirements to keep in mind.

  • Maximum 10 attachments per message
  • 2MB per attachment
  • Attachment files cannot contain line breaks, quotes, or backslashes
  • Text-based files (for example, calendar invites) require converting the string: Buffer.from(text, 'utf-8')

Volver arriba

My email isn't working

Below are some common errors that can occur and what they mean.

ErrorDescripción
Any status that's not 200Failure.
My email was accepted but not deliveredA successful call means the gateway accepted the message, but delivery happens out of your app or site. Check the spam mailbox of the recipient or log the messageId to trace delivery issues.
email ends in spam mailboxAttach a custom domain so mail comes from your own domain. Send both text and html versions of your email.
email send failedRead the error text. Common causes can be a missing field (to, subject, text and html or the from address is invalid.
email gateway unreachable: timed out after 30000msNo response within 30 seconds. If multiple attempts fail, contact a GoDaddy Guide for help.
email gateway unreachableMake sure the code runs on the server of your deployed app (not in the browser or your own computer).

Volver arriba

Más información