W
Wasp7d ago
Dada

Email Verification SMTP not working

I tried MailGun API /SMTP and tried Brevo SMTP , when i try to send email using swaks command it works , but on the app it does not work ( not in dev nor production ). when i try to signup i get status 200 but no email sent.
No description
7 Replies
kapa.ai
kapa.ai7d ago
Hi @Dada. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I understand you're having issues with email verification not working in your Wasp application. Let's troubleshoot this issue based on the information provided. Possible Causes and Solutions 1. Email Provider Configuration Make sure you've properly configured your email provider in your main.wasp file:
app Example {
...
emailSender: {
provider: SMTP, // Or Mailgun if using their API
defaultFrom: {
name: "Your App Name",
}
}
}
app Example {
...
emailSender: {
provider: SMTP, // Or Mailgun if using their API
defaultFrom: {
name: "Your App Name",
}
}
}
2. Environment Variables For SMTP, ensure you've set all required environment variables in your .env.server file:
SMTP_HOST=your-smtp-host
SMTP_USERNAME=your-username
SMTP_PASSWORD=your-password
SMTP_PORT=your-port
SMTP_HOST=your-smtp-host
SMTP_USERNAME=your-username
SMTP_PASSWORD=your-password
SMTP_PORT=your-port
For Mailgun, you need:
MAILGUN_API_KEY=your-api-key
MAILGUN_DOMAIN=your-domain
MAILGUN_API_KEY=your-api-key
MAILGUN_DOMAIN=your-domain
Learn more about SMTP configuration Learn more about Mailgun configuration 3. Email Verification Setup Check that you've properly set up email verification in your auth configuration:
emailVerification: {
clientRoute: EmailVerificationRoute,
getEmailContentFn: import { getVerificationEmailContent } from "@src/email"
}
emailVerification: {
clientRoute: EmailVerificationRoute,
getEmailContentFn: import { getVerificationEmailContent } from "@src/email"
}
4. Debug with Dummy Provider For debugging purposes, try switching to the Dummy provider temporarily to see if emails are being attempted:
emailSender: {
provider: Dummy
}
emailSender: {
provider: Dummy
}
This will log emails to the console instead of sending them, which can help identify if the issue is with your email configuration or with the email sending process itself. Note that the Dummy provider is for development only and won't work in production. Learn more about the Dummy provider 5. Check Email Sending Code If you're using a custom sign-up action, ensure your email sending code is correct:
const verificationLink = await createEmailVerificationLink(args.email, '/email-verification');
try {
await sendEmailVerificationEmail(
args.email,
{
from: {
name: "My App Postman",
},
to: args.email,
subject: "Verify your email",
text: `Click the link below to verify your email: ${verificationLink}`,
html: `
<p>Click the link below to verify your email</p>
<a href="${verificationLink}">Verify email</a>
`,
}
);
} catch (e) {
console.error("Failed to send email verification email:", e);
throw new HttpError(500, "Failed to send email verification email.");
}
const verificationLink = await createEmailVerificationLink(args.email, '/email-verification');
try {
await sendEmailVerificationEmail(
args.email,
{
from: {
name: "My App Postman",
},
to: args.email,
subject: "Verify your email",
text: `Click the link below to verify your email: ${verificationLink}`,
html: `
<p>Click the link below to verify your email</p>
<a href="${verificationLink}">Verify email</a>
`,
}
);
} catch (e) {
console.error("Failed to send email verification email:", e);
throw new HttpError(500, "Failed to send email verification email.");
}
Since you're getting a 200 status but no email, check your server logs for any error messages related to email sending. The issue might be with the email provider's configuration or with the email content itself. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Dada, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
brahyammm
brahyammm6d ago
having the same issue here, all works locally but when deploying I get 200 and no email. When checking the backend logs I see:
Failed to send email Error: Connection timeout
at SMTPConnection._formatError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:809:19)
at SMTPConnection._onError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:795:20)
at Timeout.<anonymous> (/app/node_modules/nodemailer/lib/smtp-connection/index.js:237:22)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
code: 'ETIMEDOUT',
command: 'CONN'
}
Failed to send email Error: Connection timeout
at SMTPConnection._formatError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:809:19)
at SMTPConnection._onError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:795:20)
at Timeout.<anonymous> (/app/node_modules/nodemailer/lib/smtp-connection/index.js:237:22)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
code: 'ETIMEDOUT',
command: 'CONN'
}
I deployed via CapRover following the tutorial. I tried to map/open the ports used for SMTP 465 and 587 but no luck. Do you have any suggestion?
MEE6
MEE66d ago
Wohooo @brahyammm, you just became a Waspeteer level 1!
brahyammm
brahyammm6d ago
solved, I was using port 465 in env vars but read that is usually blocked by VPS providers. luckily my email provider allows 2587 too which is not so opening that one worked.
toticozeni
toticozeni6d ago
Hello @Dada , do you have any MailGun, Brevo dashboards that show how many sucessful/failed emails you've sent? Trying to see if it's caused by wasp code or some configuration errors. Also, did you try to check the steps from kapa.ai?
Dada
DadaOP6d ago
@franjo i figured out the problem i had , in the main.wasp file , there are two places where you set the fromField . i was only setting it in emailSender object , while the field inisde auth.methods.email.fromField.email was still set to example domain , thats why it wasn't working .
toticozeni
toticozeni6d ago
Glad you got it working. 😁 👍

Did you find this page helpful?