smtp: Fix STARTTLS, request HELO once TLS is established (#15032)
This commit is contained in:
parent
911e39351e
commit
503c5e0520
1 changed files with 9 additions and 3 deletions
|
|
@ -60,6 +60,7 @@ type
|
||||||
|
|
||||||
SmtpBase[SocketType] = ref object
|
SmtpBase[SocketType] = ref object
|
||||||
sock: SocketType
|
sock: SocketType
|
||||||
|
address: string
|
||||||
debug: bool
|
debug: bool
|
||||||
|
|
||||||
Smtp* = SmtpBase[Socket]
|
Smtp* = SmtpBase[Socket]
|
||||||
|
|
@ -225,15 +226,19 @@ proc checkReply*(smtp: Smtp | AsyncSmtp, reply: string) {.multisync.} =
|
||||||
if not line.startswith(reply):
|
if not line.startswith(reply):
|
||||||
await quitExcpt(smtp, "Expected " & reply & " reply, got: " & line)
|
await quitExcpt(smtp, "Expected " & reply & " reply, got: " & line)
|
||||||
|
|
||||||
|
proc helo*(smtp: Smtp | AsyncSmtp) {.multisync.} =
|
||||||
|
# Sends the HELO request
|
||||||
|
await smtp.debugSend("HELO " & smtp.address & "\c\L")
|
||||||
|
await smtp.checkReply("250")
|
||||||
|
|
||||||
proc connect*(smtp: Smtp | AsyncSmtp,
|
proc connect*(smtp: Smtp | AsyncSmtp,
|
||||||
address: string, port: Port) {.multisync.} =
|
address: string, port: Port) {.multisync.} =
|
||||||
## Establishes a connection with a SMTP server.
|
## Establishes a connection with a SMTP server.
|
||||||
## May fail with ReplyError or with a socket error.
|
## May fail with ReplyError or with a socket error.
|
||||||
|
smtp.address = address
|
||||||
await smtp.sock.connect(address, port)
|
await smtp.sock.connect(address, port)
|
||||||
|
|
||||||
await smtp.checkReply("220")
|
await smtp.checkReply("220")
|
||||||
await smtp.debugSend("HELO " & address & "\c\L")
|
await smtp.helo()
|
||||||
await smtp.checkReply("250")
|
|
||||||
|
|
||||||
proc startTls*(smtp: Smtp | AsyncSmtp, sslContext: SSLContext = nil) {.multisync.} =
|
proc startTls*(smtp: Smtp | AsyncSmtp, sslContext: SSLContext = nil) {.multisync.} =
|
||||||
## Put the SMTP connection in TLS (Transport Layer Security) mode.
|
## Put the SMTP connection in TLS (Transport Layer Security) mode.
|
||||||
|
|
@ -245,6 +250,7 @@ proc startTls*(smtp: Smtp | AsyncSmtp, sslContext: SSLContext = nil) {.multisync
|
||||||
getSSLContext().wrapConnectedSocket(smtp.sock, handshakeAsClient)
|
getSSLContext().wrapConnectedSocket(smtp.sock, handshakeAsClient)
|
||||||
else:
|
else:
|
||||||
sslContext.wrapConnectedSocket(smtp.sock, handshakeAsClient)
|
sslContext.wrapConnectedSocket(smtp.sock, handshakeAsClient)
|
||||||
|
await smtp.helo()
|
||||||
else:
|
else:
|
||||||
{.error: "SMTP module compiled without SSL support".}
|
{.error: "SMTP module compiled without SSL support".}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue