Mail is not sending · Issue #7 · postalserver/postal-node · GitHub
Skip to content

Mail is not sending #7

Open
Open

Description

@zain-bryxo

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

Activity

  1. bitbay commented on Sep 24, 2024

    @bitbay

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions