Dịch vụ lưu trữ GoDaddy Node.js Trợ giúp

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.

Về đầu trang

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: "..." }

Về đầu trang

Email code requirements and options

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

TrườngBắt buộcMô tả
toCóRecipient addresses. At least one is required.
subjectCóThe subject line
text or htmlAt least one (both are ok)Text or HTML body
ccKhôngCarbon-copy recipients
bccKhôngBlind-copy recipients
replyToKhôngWhere replies go (for example, the visitor that filled out a contact form)
attachmentsKhôngFiles to attach
contentTypeKhôngHow to interpret attached files
fromKhôngSender 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).

Về đầu trang

How do attachments work?

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

TrườngBắt buộcMô tả
filenameCóThe file name the recipient sees (for example, invoice.pdf)
contentCóThe file’s contents.
contentTypeKhôngThe 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')

Về đầu trang

My email isn't working

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

LỗiMô tả
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).

Về đầu trang

Xem thêm thông tin