Skip to content

Commit

Permalink
fix smtp server greeting error
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbr0wn committed Aug 25, 2024
1 parent 5dcc857 commit af72dc8
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions internal/mailserver/mailserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func VerifyEmailAddress(email, fromDomain, fromEmail string, dnsRecords dns.DNS)
var conn net.Conn
var client *bufio.Reader
var err error
var connected bool
var greetCode string
var greetDesc string

Expand All @@ -52,12 +51,11 @@ func VerifyEmailAddress(email, fromDomain, fromEmail string, dnsRecords dns.DNS)
}
greetCode, greetDesc = readSMTPgreeting(client)
if greetCode == "220" {
connected = true
break
}
}

if !connected {
if greetCode != "220" {
results.CanConnectSmtp = false
results.ResponseCode = greetCode
results.Description = greetDesc
Expand Down Expand Up @@ -126,10 +124,9 @@ func readSMTPgreeting(smtpClient *bufio.Reader) (string, string) {
line = strings.TrimSpace(line)

// Check if this is the last line of the greeting
if strings.HasPrefix(line, "220") {
// This is the final greeting line
if strings.HasPrefix(line, "220") || strings.HasPrefix(line, "220-") {
return "220", ""
} else if !strings.HasPrefix(line, "220-") {
} else {
// If the line doesn't start with 220- or 220, it's an unexpected response
code, desc := parseSmtpCommand(line)
return code, desc
Expand Down Expand Up @@ -243,6 +240,7 @@ func parseSmtpCommand(response string) (string, string) {

// Extract the rest of the message
message := strings.TrimSpace(response[3:])
message = strings.TrimPrefix(message, "-")

return statusCode, message
}

0 comments on commit af72dc8

Please sign in to comment.