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

Mail is not sending #7

Open
zain-bryxo opened this issue Jul 19, 2024 · 1 comment
Open

Mail is not sending #7

zain-bryxo opened this issue Jul 19, 2024 · 1 comment

Comments

@zain-bryxo
Copy link

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" }
            }
        }

with this error message


node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: write EPROTO 78260000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:c:\ws\deps\openssl\openssl\ssl\record\rec_layer_s3.c:1590:SSL alert number 80

    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:95:16) {
  errno: -4046,
  code: 'EPROTO',
  syscall: 'write'
}

Node.js v20.13.1
[nodemon] app crashed - waiting for file changes before starting...

Any solution for it please

@bitbay
Copy link

bitbay commented Sep 24, 2024

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.

const mail = {
    to: "<my-mail>",
    from: "<from-mail>",
    subject: "test mail",
    plain_body: plainBody,
    html_body: htmlBody
}

try {
    await fetch(
        new Request(`${my host}/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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants