dword-design / nuxt-mail

Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
Other
247 stars 18 forks source link

500 on localhost and production for SMTP non-GMAIL #210

Closed danieldanielecki closed 1 year ago

danieldanielecki commented 1 year ago

Hey, I'm trying to have it working in Nuxt3 app, but even after browsing through the issues, I can't find a workable solution.

That's what I can see on production (deployed on Firebase, URL: https://doyban.com/contact):

Request URL: https://doyban.com/mail/send
Request Method: POST
Status Code: 500 Internal Server Error
Remote Address: 199.36.158.100:443
Referrer Policy: strict-origin-when-cross-origin
Screenshot 2023-11-06 at 05 50 01

It's deployed with nuxi build and using Firebase Functions, tried this even with nuxi generate, then the error was 404. Yes, I know the docs mentions Does not work for static sites (via nuxt generate) because the module creates a server route., but I wanted to debug further.

Screenshot 2023-11-04 at 17 51 26

On localhost:

Request URL: http://localhost:3000/mail/send
Request Method: POST
Status Code: 500 Hostname/IP does not match certificate's altnames: Host: mail.doyban.com. is not in the cert's altnames: DNS:h6.idhosting.pl
Remote Address: 127.0.0.1:3000
Referrer Policy: strict-origin-when-cross-origin

Note: I checked with the domain provider where mail is hosted about using h6.idhosting.pl, and they recommended to use mail.doyban.com. I got the confirmation of port 587 being the correct as well.

Screenshot 2023-11-04 at 17 49 39

Here's with h6.idhosting.pl deployed, the same effect:

Screenshot 2023-11-04 at 18 18 54

Here's with h6.idhosting.pl on localhost, 500 Can't send mail - all recipients were rejected: 554 5.7.1 <dhcp-077-248-184-129.chello.nl[77.248.184.129]>: Client host rejected: Access denied this time.

Screenshot 2023-11-04 at 18 25 42

The repo is publicly available: https://github.com/Doyban/Doyban-Website, I'd appreciate help, as it must be something really trivial.

I also tried it with gmail and it returns 200 on localhost:

Screenshot 2023-11-06 at 06 01 25

and it was delivered:

Screenshot 2023-11-06 at 06 03 32

Deployed with gmail and it returns 200 on production:

Screenshot 2023-11-06 at 06 06 25

and it was delivered:

Screenshot 2023-11-06 at 06 06 57
dword-design commented 1 year ago

@danieldanielecki Phew yeah sounds like a config issue related to your server/domain. Unfortunately I'm not an expert on this field since I'm mainly doing frontend. Maybe someone else can help here or has a similar issue.

danieldanielecki commented 1 year ago

@dword-design, is it possible to include auth object for non-gmail SMTP?

dword-design commented 1 year ago

@danieldanielecki I guess it should be possible. The smtp object is passed to node-mailer as-is.

danieldanielecki commented 1 year ago

Got it working, thanks to adding auth for non-Gmail SMTP based on my (very) old project (https://github.com/Ditectrev/ditectrev.com-v3/blob/master/server/main.ts#L214-L225) where I used nodemailer itself.

Additionally, my domain provider was wrong, and indeed I had to use h6.idhosting.pl lol!

My final solution, works on localhost and in prod!! Hopefully will save some time to others :)

[
  'nuxt-mail',
  {
     message: {
       to: 'contact@doyban.com',
     },
     smtp: {
       host: process.env.MAIL_HOST,
       port: process.env.MAIL_PORT,
       auth: {
         user: process.env.MAIL_ACCOUNT,
         pass: process.env.MAIL_PASSWORD,
       },
    },
  },
],

process.env values are of course coming from environmental variables in .env.