-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
Description
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)
tobico