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

[Regression] Supabase edge functions v1.4.0 works, v1.5.0 and later doesn't #82

Open
mjp-free-tech opened this issue Nov 19, 2023 · 1 comment
Assignees
Labels
bug Something isn't working triage

Comments

@mjp-free-tech
Copy link

I have write some code to send emails using supabase edge function. Using library of 1.4.0 all works good, but 1.5.0 and 1.6.0 doesn't works

Code:

import { SMTPClient } from 'https://deno.land/x/[email protected]/mod.ts'
import { decode } from "https://deno.land/x/[email protected]/mod.ts";
import { corsHeaders } from "../_shared/cors.ts";

const MIN_ACCESS_LEVEL = 2;
const SMTP_FROM = Deno.env.get('SMTP_FROM');
const options = {
  connection: {
    hostname: Deno.env.get('SMTP_HOST'),
    port: Number(Deno.env.get('SMTP_PORT')),
    tls: false,
    auth: {
      username: Deno.env.get('SMTP_USER'),
      password:  Deno.env.get('SMTP_PASS'),
    },
  },
  debug: {
    log: true,
    allowUnsecure: true,
    encodeLB: false,
    noStartTLS: false,
  },
};

Deno.serve(async (req) => {
  if (req.method === 'OPTIONS') {
    return new Response('ok', { headers: corsHeaders })
  }

  const jwt = req.headers.get("Authorization")?.split(' ')[1];
  const [_header, payload, _signature] = decode(jwt);

  const accessLevel = payload?.app_metadata?.appClaims?.accessLevel;

  if (typeof accessLevel !== 'number' || accessLevel < MIN_ACCESS_LEVEL) {
    return new Response(null, { status: 403 });
  }

  const requestBody = await req.json();
  const { to, subject, content } = requestBody;
  const from = SMTP_FROM;
  const message = { from, to, subject, content };

  const smtp = new SMTPClient(options);
  await smtp.send(message);
  
  const data = { status: "ok" };

  return new Response(
    JSON.stringify(data),
    { headers: { ...corsHeaders, "Content-Type": "application/json" } },
  );
});

Error stack trace:

BadResource: TCP stream is currently in use
    at opStartTls (ext:deno_net/02_tls.js:10:15)
    at Object.startTls (ext:deno_net/02_tls.js:88:57)
    at #prepareConnection (https://deno.land/x/[email protected]/client/basic/client.ts:196:37)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async https://deno.land/x/[email protected]/client/basic/client.ts:35:13
    at async SMTPClient.send (https://deno.land/x/[email protected]/client/basic/client.ts:49:9)


@mjp-free-tech mjp-free-tech added bug Something isn't working triage labels Nov 19, 2023
@tobico
Copy link

tobico commented Nov 30, 2023

I'm seeing the same error using denomailer in a Supabase edge function. Downgrading to 1.4.0 resolves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

3 participants