Closed getofmeland closed 9 months ago
Hi @getofmeland,
can you conform your contact settings.
so run npm run dev
and npm run cms-proxy-server
and go to:
http://localhost:4321/admin#/collections/config/entries/contact
what is the provider you see?
I see all 3 but Postmark is selected
I also have my postmark server api key listed in my .env file in the root
I am using netlify for my deployment if that helps
Postmark should work,
the SLACK_TOKEN undefined
was just a console log on the slack endpoint.
Take a look at the response to see why postmark is not sending your email you can check your console if you are running netlify dev
or if it is on netlify check the edge functions
log
[contact-postmark] {
ErrorCode: 412,
Message: "While your account is pending approval, all recipient addresses must share the same domain as the 'F"... 143 more characters
Have tried Mailgun as well and I am getting literally the same message, and nothing in the edge functions logs either.
can you check the network response of the form submit?
So saying Mailgun configuration is missing from the .env file, I have checked my .env file and the configuration is there:
Not sure what I am missing...
Where are you hosting the site, netlify?
the error comes from an edge / deno function:
let {
MAILGUN_API_KEY,
MAILGUN_API_URL,
MAILGUN_DOMAIN,
FROM_EMAIL_ADDRESS,
TO_EMAIL_ADDRESS,
} = Deno.env.toObject();
export default async (request, context) => {
if (
!MAILGUN_API_KEY ||
!FROM_EMAIL_ADDRESS ||
!TO_EMAIL_ADDRESS ||
!MAILGUN_API_URL
)
return Response.json({
error: "Missing MailGun configuration, please check your .env file.",
});
Can you console.log the Deno.env.toObject()
to see if they are available?
Will have a look, the site is hosted with netlify.
Sent from Outlook for iOShttps://aka.ms/o0ukef
From: preetamslot @.> Sent: Saturday, January 20, 2024 12:34:39 PM To: unfolding-io/nebulix @.> Cc: Charlie Gough @.>; Mention @.> Subject: Re: [unfolding-io/nebulix] Postmark configuration (Issue #31)
Where are you hosting the site, netlify?
the error comes from an edge / deno function:
let { MAILGUN_API_KEY, MAILGUN_API_URL, MAILGUN_DOMAIN, FROM_EMAIL_ADDRESS, TO_EMAIL_ADDRESS, } = Deno.env.toObject();
export default async (request, context) => { if ( !MAILGUN_API_KEY || !FROM_EMAIL_ADDRESS || !TO_EMAIL_ADDRESS || !MAILGUN_API_URL ) return Response.json({ error: "Missing MailGun configuration, please check your .env file.", });
Can you console.log the Deno.env.toObject() to see if they are available?
— Reply to this email directly, view it on GitHubhttps://github.com/unfolding-io/nebulix/issues/31#issuecomment-1902083413, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQGO5EWEOYDP232AQG4I65LYPO2V7AVCNFSM6AAAAABB5QYRNWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBSGA4DGNBRGM. You are receiving this because you were mentioned.Message ID: @.***>
Having made a change it appears the script for mailgun isn't picking up the Environmental Variables:
Jan 20, 09:57:43 PM: info [Object: null prototype] {Jan 20, 09:57:43 PM: info DENO_REGION: "aws-eu-central-1",Jan 20, 09:57:43 PM: info UNITS: "metric",Jan 20, 09:57:43 PM: info SHOP_SLUG: "shop",Jan 20, 09:57:43 PM: info CURRENCY: "GBP",Jan 20, 09:57:43 PM: info WEBSITE_LANGUAGE: "en",Jan 20, 09:57:43 PM: info BLOG_SLUG: "blog",Jan 20, 09:57:43 PM: info MENU_SLUG: "menu",Jan 20, 09:57:43 PM: info DENO_DEPLOYMENT_ID: "CD_vAvvpuOZU_j2brJ96HFhCd5idqZku2-Y1XvGkVbw=",Jan 20, 09:57:43 PM: info NODE_VERSION: "18",Jan 20, 09:57:43 PM: info PORTFOLIO_SLUG: "work"Jan 20, 09:57:43 PM: info }
It appears that they are not even being pulled in via the script, as this returns undefined
So in addition to this, I added these into the Netlify Environmental Variables and they are pulled in...
When I submit the form I now get a new error:
uncaught exception during edge function invocation
It appeared to be linked to the encode function, I have updated the script to as follows:
import { encodeBase64 } from "https://deno.land/std/encoding/base64.ts";
let {
MAILGUN_API_KEY,
MAILGUN_API_URL,
MAILGUN_DOMAIN,
FROM_EMAIL_ADDRESS,
TO_EMAIL_ADDRESS,
} = Deno.env.toObject();
// Get the environment variables as an object
const envObject = Deno.env.toObject();
// Log the object to the console
console.log(envObject);
export default async (request, context) => {
if (
!MAILGUN_API_KEY ||
!FROM_EMAIL_ADDRESS ||
!TO_EMAIL_ADDRESS ||
!MAILGUN_API_URL
)
return Response.json({
error: "Missing MailGun configuration, please check your .env file.",
});
const { email, name, message, topicEmail } = await request.json();
if (!email || email === "") return Response.json({ error: "Missing email" });
const authHeader = "Basic " + encodeBase64(`api:${MAILGUN_API_KEY}`);
const headers = {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/x-www-form-urlencoded",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Methods": "OPTIONS,POST,GET",
Authorization: authHeader,
};
let payload = new URLSearchParams();
payload.append("from", FROM_EMAIL_ADDRESS);
payload.append("to", topicEmail ? topicEmail : TO_EMAIL_ADDRESS);
payload.append("h:Reply-To", email);
payload.append("subject", `Contact Form: ${name} ${email}`);
payload.append("text", message);
try {
const resp = await fetch(
`${MAILGUN_API_URL}/v3/${MAILGUN_DOMAIN}/messages`,
{
method: "POST",
headers: headers,
body: payload,
},
);
let response = await resp.json();
return Response.json({
statusCode: 200,
status: resp?.ok ? "ok" : "error",
body: "Your message was sent successfully! We'll be in touch.",
});
} catch (e) {
console.log("ERROR:", e);
return Response.json({
statusCode: 400,
status: "error",
error: "Mailgun error",
});
}
};
Thanks! strange that encode works local but not on netlify. I have updated the function.
Discussed in https://github.com/unfolding-io/nebulix/discussions/30