Question

App Platform contact email

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.


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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.

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