nim-lang / smtp

SMTP client implementation, adapted from the Nim standard library
MIT License
10 stars 5 forks source link

Ubuntu 20.04 + Nim v2.0 + smtp = No valid socket error code available #12

Open ThomasTJdev opened 5 months ago

ThomasTJdev commented 5 months ago

Description

Very basic code example sending emails works fine - besides when being deployed on Ubuntu 20.04.

Info

Code snippet Identical to the mail code example.

var msg = createMessage("Hello from Nim's SMTP",
                        "Hello!.\n Is this awesome or what?",
                        @["foo@gmail.com"])
let smtpConn = newSmtp(useSsl = true, debug=true)
smtpConn.connect("smtp.gmail.com", Port 465)
smtpConn.auth("username", "password")
smtpConn.sendmail("username@gmail.com", @["foo@gmail.com"], $msg)

Nim Version

# Ubuntu 20.04 - not working env

$ openssl version
OpenSSL 1.1.1f  31 Mar 2020

$ nim -v
Nim Compiler Version 2.0.2 [Linux: amd64]
Compiled at 2023-12-15
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: c4c44d10df8a14204a75c34e499def200589cb7c
active boot switches: -d:release

Current Output

$ nim c -d:dev -d:ssl -r email_test.nim
/home/user/tmp/email_test.nim(6) email_test
/home/user/.nimble/pkgs/smtp-0.1.0/smtp.nim(267) connect
/home/user/.nimble/pkgs/smtp-0.1.0/smtp.nim(227) checkReply
/home/user/.nimble/pkgs/smtp-0.1.0/smtp.nim(109) debugRecv
/home/user/.choosenim/toolchains/nim-2.0.2/lib/pure/net.nim(1654) recvLine
/home/user/.choosenim/toolchains/nim-2.0.2/lib/pure/net.nim(1602) readLine
/home/user/.choosenim/toolchains/nim-2.0.2/lib/pure/net.nim(941) getSocketError
/home/user/.choosenim/toolchains/nim-2.0.2/lib/std/oserrors.nim(92) raiseOSError
Error: unhandled exception: Additional info: No valid socket error code available [OSError]

Expected Output

No response

Possible Solution

No response

Additional Information

No response

tmiad2 commented 5 months ago

You very likely already know this, but you usually need to have elevated permissions to bind to low numbered ports. Have you tried the same process with root permissions?

ThomasTJdev commented 5 months ago

Thanks for the suggestion @tmiad2 . Running as root makes no difference. Examples below failes with Nim 2.0.2, but runs fine with Nim 1.6.18.

-d:release

$ sudo ./email_test
[sudo] password for user: 
oserrors.nim(92)         raiseOSError
Error: unhandled exception: Additional info: No valid socket error code available [OSError]

-d:dev

$ sudo ./email_test
/home/user/tmp/email_test.nim(6) email_test
/home/user/.nimble/pkgs2/smtp-0.1.0-6c799a1929f178017e7f1b47a8f73f8882acda66/smtp.nim(267) connect
/home/user/.nimble/pkgs2/smtp-0.1.0-6c799a1929f178017e7f1b47a8f73f8882acda66/smtp.nim(227) checkReply
/home/user/.nimble/pkgs2/smtp-0.1.0-6c799a1929f178017e7f1b47a8f73f8882acda66/smtp.nim(109) debugRecv
/home/user/.choosenim/toolchains/nim-2.0.2/lib/pure/net.nim(1654) recvLine
/home/user/.choosenim/toolchains/nim-2.0.2/lib/pure/net.nim(1602) readLine
/home/user/.choosenim/toolchains/nim-2.0.2/lib/pure/net.nim(941) getSocketError
/home/user/.choosenim/toolchains/nim-2.0.2/lib/std/oserrors.nim(92) raiseOSError
Error: unhandled exception: Additional info: No valid socket error code available [OSError]
ThomasTJdev commented 3 months ago

I can confirm that PR https://github.com/nim-lang/smtp/pull/11 solves this issue