https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • d

    dave

    02/19/2023, 5:57 PM
    How do I set it to be a Worker that I've already created?
  • k

    kian

    02/19/2023, 5:57 PM
    It'll need an email handler to be recognised as an email Worker I suppose
  • d

    dave

    02/19/2023, 5:59 PM
    hmm do I just need to export an
    email
    function?
  • d

    dave

    02/19/2023, 5:59 PM
    lemme try that unless you say no 😛
  • k

    kian

    02/19/2023, 5:59 PM
    Yep, same as fetch/scheduled/queue/etc
  • k

    kian

    02/19/2023, 5:59 PM
    Copy code
    ts
    export default <ExportedHandler> {
      async email(msg, env, ctx) {
        console.log('blob');
      }
    }
  • d

    dave

    02/19/2023, 6:00 PM
    I currently have:
    Copy code
    const app = new Hono<{ Bindings: Env }>()
    export default app
    Can I add the email handler to this?
  • k

    kian

    02/19/2023, 6:03 PM
    Copy code
    js
    export default {
      fetch: app.fetch,
      async email(...) {...}
    }
  • d

    dave

    02/19/2023, 6:04 PM
    I only need the fetch exported?
  • h

    HardAtWork

    02/19/2023, 6:04 PM
    The example exports fetch and email
  • k

    kian

    02/19/2023, 6:05 PM
    Hono is only for
    fetch
    events - if you want to do scheduled/email/queue/etc then you just do those separately and pass
    app.fetch
    to your exported
    fetch
    handler
  • d

    dave

    02/19/2023, 6:07 PM
    interesting, trying it now
  • d

    dave

    02/19/2023, 6:08 PM
    hmm is EmailMessage not already definted?
  • k

    kian

    02/19/2023, 6:08 PM
    it's in workers-types
  • d

    dave

    02/19/2023, 6:09 PM
    oh I see I'm using 3.0.0
  • d

    dave

    02/19/2023, 6:12 PM
    ah yep
  • d

    dave

    02/19/2023, 6:14 PM
    ahh yep now I see my Worker!
  • d

    dave

    02/19/2023, 6:14 PM
    thanks!
  • d

    dave

    02/19/2023, 6:14 PM
    this was my code in the end:
    Copy code
    typescript
    export default {
        fetch: app.fetch,
        async email(message: EmailMessage, env: Env, ctx: ExecutionContext) {
            console.debug("email!")
            console.debug(JSON.stringify(message, null, 2))
        }
    }
  • d

    dave

    02/19/2023, 9:47 PM
    Is there a way to locally test email Workers?
  • d

    dave

    02/19/2023, 9:55 PM
    huh odd, my catch-all Worker isn't triggering, but the email still gets forwarded.
  • d

    dave

    02/19/2023, 9:55 PM
    how the frig
  • d

    dave

    02/19/2023, 9:57 PM
    I can see it's going through CF.
  • d

    dave

    02/19/2023, 9:58 PM
    is there some latency after enabling a Worker?
  • d

    dave

    02/19/2023, 9:58 PM
    alright a direct email without the subdomain works
  • h

    HardAtWork

    02/19/2023, 10:00 PM
    How'd you get multi-level-subdomain emails working?
  • d

    dave

    02/19/2023, 10:00 PM
    yay it's working, it was latency
  • d

    dave

    02/19/2023, 10:01 PM
    just added the DNS entries myself
  • h

    HardAtWork

    02/19/2023, 10:01 PM
    Oh derp
  • d

    dave

    02/19/2023, 10:02 PM
    The UI still freaks out.
1...229022912292...2509Latest