Commit a7dd17c
feat(email-resend): add Custom headers for the Resend adapter (#15645)
After some trying (and failing) to enable unsubscribe headers, I found
that the Resend adapter does not pass custom headers from the Payload
sendEmail options to the Resend API. When attempting to send an email
with custom headers, they are ignored because the
`mapPayloadEmailToResendEmail` function creates a new object that
excludes the headers property.
```
await payload.sendEmail({
from: "Test <test@domain.com>",
to: "jimmybillbob@example.com",
subject: "Resend adapter does not allow custom headers :(",
html: html,
headers: {
"List-Unsubscribe": "<https://domain.com/unsubscribe>",
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
},
});
```
I have recitified this by adding `headers: message.headers,` to the
`mapPayloadEmailToResendEmail` in `packages/email-resend/src/index.ts`,
as below.
```
function mapPayloadEmailToResendEmail(
message: SendEmailOptions,
defaultFromAddress: string,
defaultFromName: string,
): ResendSendEmailOptions {
return {
// Required
from: mapFromAddress(message.from, defaultFromName, defaultFromAddress),
subject: message.subject ?? '',
to: mapAddresses(message.to),
// Other To fields
bcc: mapAddresses(message.bcc),
cc: mapAddresses(message.cc),
reply_to: mapAddresses(message.replyTo),
// Optional
attachments: mapAttachments(message.attachments),
html: message.html?.toString() || '',
text: message.text?.toString() || '',
headers: message.headers, // Added this line.
} as ResendSendEmailOptions
}
```
---------
Co-authored-by: Paul Popus <paul@payloadcms.com>1 parent 4179bf3 commit a7dd17c
2 files changed
Lines changed: 109 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
155 | 237 | | |
156 | 238 | | |
157 | 239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
165 | 192 | | |
166 | 193 | | |
167 | 194 | | |
| |||
0 commit comments