Closed molul closed 12 months ago
Ok, I figured out a fix. I'll leave it here so maybe @dword-design updates the readme.md.
First of all, having the same email address for sender and recipient is NOT a problem. The problem is the needed Gmail configuration.
Also, I confirm that the app specific password must be typed as it is, with the format "xxxx xxxx xxxx xxxx" with spaces.
The config that worked for me was:
[
"nuxt-mail",
{
message: {
to: import.meta.env.VITE_SMTP_ADDRESS,
},
smtp: {
host: "smtp.gmail.com",
port: 587,
secure: false,
requireTLS: true,
auth: {
user: import.meta.env.VITE_SMTP_ADDRESS,
pass: import.meta.env.VITE_SMTP_PASSWORD,
},
},
},
],
On the other hand, I had the variables VITE_SMTP_ADDRESS and VITE_SMTP_PASSWORD defined in my .env file (and also in Vercel).
What is different from the info in the readme document: -I removed the line with "service: 'gmail'". I tested putting it back in, and the email wasn't sent again, so I guess this shouldn't be set in the config. -I added the lines host: "smtp.gmail.com", "port: 587", "secure: false" and "requireTLS: true".
This config sends the email in a couple of seconds, so I guess it's the way to go. Hope it helps :)
PS: one more thing that might be useful. This is my sendEmail function (for a form that has name, email and message fields):
mail.send({
from: import.meta.env.VITE_SMTP_ADDRESS,
subject: "[Web contact form] Message from " + name.value,
replyTo: name.value + " <" + email.value + ">",
text: message.value,
});
For those who haven't worked with Nodemailer yet, with the "replyTo" field, although the email sender address is your own email address, when you click "Reply", the recipient of your reply will be the one who filled the contact form.
@molul Ok cool thanks for investigating. Do you know if we need to set secure
and requireTLS
to false
or does it also with without? Since I guess it would be cool to have a setup for Gmail without disabling security mechanisms. And does the app-specific password also work without spaces? Since the spaces feel odd to me and I also used it without spaces. Still weird that the service: 'gmail'
doesn't work for you since I'm using it too.
Hi there! I tried those two things:
-Removing both "secure" and "requireTLS" lines doesn't seem to affect. The email is correctly sent too. I got those lines from some example (in stackoverflow, I think), but didn't try without them when I saw the email was finally being sent.
-And yes, the app-specific password works without spaces.
So this config should be enough to get emails being sent:
[
"nuxt-mail",
{
message: {
to: import.meta.env.VITE_SMTP_ADDRESS,
},
smtp: {
host: "smtp.gmail.com",
port: 587,
auth: {
user: import.meta.env.VITE_SMTP_ADDRESS,
pass: import.meta.env.VITE_SMTP_PASSWORD,
},
},
},
],
Hope it helps!
@molul I documented this option of configuring Gmail.
When sending emails with nuxt-mail, I'm getting the error message "connect ETIMEDOUT 173.194.76.108:465" after a few seconds.
I followed what's said on the readme (https://github.com/dword-design/nuxt-mail#readme), so I created an app specific password in Gmail and I have this in my nuxt.config.ts (note that when I type I actually mean "blabla@gmail.com"):
And this is the function I use for sending the email:
I've also tried this config in nuxt.config.ts, but no luck:
There must be something I'm missing (maybe using the same gmail address for sending and receiving is not correct?), but I can't figure out what. Any hint would be greatly appreciated :)