You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried this code in node js 20+ version but it is not working and showing error
export async function HttpApiPostalserver(plainBody, htmlBody) {
try {
var client = new postal.Client(
"my host",
"My api key",
);
let message = new postal.SendMessage(client);
message.to(<my-mail>);
message.from(<from-mail>);
message.subject("test mail");
message.plainBody(plainBody);
message.htmlBody(htmlBody);
const result = await message.send();
if (result) {
return { success: true, message: "Email sent successfully" }
}
var recipients = result.recipients();
for (var email in recipients) {
var messageSended = recipients[email];
if (messageSended.id()) {
console.log(messageSended.id()); // Logs the message ID
console.log(messageSended.token()); // Logs the message's token
return {
success: true,
id: message.id(),
message: "Email sent successfully"
}
} else {
return { error: "Failed to send mail" }
}
}
To me it seems like an OpenSSL issue.
Try to debug the connection itself, maybe curl will give You more details on what is failing.
$ curl -vv -X POST https://your_postal_server/api/v1/send/message
Obviously this should "fail" since You are not sending API key in the headers, nor payload, but if You have issues with the certificates (are they self-signed?) it should show up.
As an alternative, try a no-dependency send inside nodejs to get maybe more info on what is failing.
constmail={to: "<my-mail>",from: "<from-mail>",subject: "test mail",plain_body: plainBody,html_body: htmlBody}try{awaitfetch(newRequest(`${myhost}/api/v1/send/message`,{method: 'POST',body: JSON.stringify(mail),headers: {'Content-Type': 'application/json','X-Server-API-Key': "My api key"}}))}catch(error){console.log(error)}
I tried this code in node js 20+ version but it is not working and showing error
with this error message
Any solution for it please
The text was updated successfully, but these errors were encountered: