Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG + FIX - Verification email uses defaultFromName instead of defaultFromEmail #225

Closed
mcornielje090404 opened this issue May 17, 2024 · 2 comments · Fixed by payloadcms/payload#6442
Assignees

Comments

@mcornielje090404
Copy link

mcornielje090404 commented May 17, 2024

Hey,

I've been using the verify email flow from Payload and noticed that there's a bug with the way the verification email is sent.

When sending an email it is failing because the "address" used is the name passed into the email provider. This (in my use case) is causing Resend to block the email because it's not from a valid domain.

I've identified it to be in the file packages/payload/src/auth/sendVerificationEmail.ts

I believe you should just have to change the sendEmail function call at line 68 from

email.sendEmail({
      from: `"${email.defaultFromName}" <${email.defaultFromName}>`,
      html,
      subject,
      to: user.email
})

To:

email.sendEmail({
      from: `"${email.defaultFromName}" <${email. defaultFromAddress}>`,
      html,
      subject,
      to: user.email
})
@mcornielje090404
Copy link
Author

Btw is there any way to make PR's to payload from outside the org? I'd happily raise a PR resolving this myself if possible.

@JessChowdhury
Copy link
Member

@mcornielje090404 you can absolutely make a PR directly to Payload by forking the main repo here. Check out our contributing guidelines for some extra info when it comes to opening a PR.

I'll take a look at this issue too.

@JessChowdhury JessChowdhury self-assigned this May 20, 2024
@JessChowdhury JessChowdhury linked a pull request May 21, 2024 that will close this issue
3 tasks
JessChowdhury added a commit to payloadcms/payload that referenced this issue May 21, 2024
## Description

Closes
[#225](payloadcms/payload-3.0-demo#225).

The user verification emails are not being sent and this error is shown:
```ts
APIError: Error sending email: 422 validation_error - Invalid `from` field. The email address needs to follow the `email@example.com` or `Name <email@example.com>` format.
```

The issue is resolved by updating the `from` property on the outgoing
verification email:
```ts
from: `"${email.defaultFromName}" <${email.defaultFromName}>`,
// to
from: `"${email.defaultFromName}" <${email. defaultFromAddress}>`,
```

**NOTE:** This was not broken in 2.0, see correct outgoing email
[here](https://github.com/payloadcms/payload/blob/main/packages/payload/src/auth/sendVerificationEmail.ts#L69).

- [X] I have read and understand the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository.

## Type of change

- [X] Bug fix (non-breaking change which fixes an issue)

## Checklist:

- [X] Existing test suite passes locally with my changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants