Email integration problem in branch deploy?

Hi, hoping someone can tell me if I’m missing something obvious. I am adding 2 new forms to a site and need to use the Netlify email integration with SendGrid to send slightly richer notifications than the standard netlify emails. The Netlify subdomain is usradiology.netlify.app.

I’ve successfully set up a similar integration on another site that has been in production and is working well. And on the current site it works fine when running locally with netlify dev — I receive the email a few seconds after submitting the form.

But when I try to test it from a branch deploy, the email is not sent. I don’t see any errors in the build process, and the function log seems to indicate the function runs successfully when the form is submitted. The form data does show up in the Netlify Forms ui. But the custom email is not received, and according to my SendGrid activity log nothing was sent to SendGrid. This is an example of what I see in the function log:
Jun 15, 03:35:04 PM: b553a03e Duration: 261.44 ms Memory Usage: 74 MB Init Duration: 202.50 ms

Any suggestions for a likely cause for this issue or where to look for clues? Hopefully I missed something simple. Like maybe it’s not even supposed to work in a branch deploy?

Thanks!

Hi @Mike_McPhillips can you share how you setup your form and maybe a link to your fully function log?

Hi @SamO Everything works as expected in Netlify dev, but on a branch deploy the emails are not sent.

I believe the problem is that we are using the process.env.URL variable in the path for the emails in our submission-created function. That variable targets the production site but the email templates are not on the production branch yet. I tried using DEPLOY_PRIME_URL instead or URL, but that resulted in an error — in the function log it was undefined.

Then I tried hard-coding the branch deploy url and the emails did work. So I think all I need to do now is to figure out how to automatically replace that portion of the path with the appropriate url.

Like this: new URL(event.rawUrl).origin would give you https:// + domain + tld

Thank you @hrishikesh! That was exactly what I needed.