Report this

What is the reason for this report?

App Platform contact email

Posted on March 2, 2022

Hello,

I’m new to the app platform. Currently I’m working on a NuxtJS static site and everything is working as expected.

The one thing I can’t seem to find in the docs or here in the community is regarding sending an email with a contact form using Nuxt. For examples other services, such Netlify or Firebase, offer functions that allow you to execute some code in the server and do such things. I don’t know if that is possible here in DO App platform.

What I need is quite simple, after the form is validated I want to send an email to a specific address with the fields of the form.

Thanks in advance!!!

Cheers, Rodrigo.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

What I would personally do in such case is to use an SMTP package like nuxt-mail mail for example:

https://www.npmjs.com/package/nuxt-mail

You can install it with:

npm install nuxt-mail

And then you could then specify your SMTP details in your nuxt.config.js file:

export default {
  modules: [
    '@nuxtjs/axios',
    ['nuxt-mail', {
      message: {
        to: 'foo@bar.de',
      },
      smtp: {
        host: "smtp.example.com",
        port: 587,
      },
    }],
  ],
  // or use the top-level option:
  mail: {
    message: {
      to: 'foo@bar.de',
    },
    smtp: {
      host: "smtp.example.com",
      port: 587,
    },
  },
}

The module injects the $mail variable, which we now use to send emails:

// Inside a component
this.$mail.send({
  from: 'John Doe',
  subject: 'Incredible',
  text: 'This is an incredible test message',
})

Note that you would need an SMTP service so that you could set the details correctly in the config file. If you do not have one already, you could use SendGrid for example. They offer a free package which is sufficient for such use cases.

Hope that this helps!

Best,

Bobby

Sounds like you’re serving a static (built) website, you need something to handle the backend logic for your forms, such as a node (express) backend and a database to store data, and a mail provider to send out a confirmation email.

You can certainly achive this in DO but you’ll have to do some additional work. You can do basic form validation on the client side, but you should also sanitize server side. You’ll need to write some logic, and have a server app running using a droplet or you can use a cloud function (serverless) if not that complex.

The suggestion for Nuxt is a good one. However, a feature similar to Netlify’s would be very useful for frameworks like Gatsby and NextJS.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.