Sign in to follow this  
Followers 0
maqleod

_InetSmtpMail() - how to modify to just verify mailbox exists

1 post in this topic

I need a function that just validates that the target mailbox exists, but doesn't actually send anything. Since _InetSmtpMail() already does the work of finding and connecting to the mail server on the other end, I figured it would be a good place to start with this.

If $s_SmtpServer = "" Or $s_FromAddress = "" Or $s_ToAddress = "" Or $s_FromName = "" Or StringLen($s_FromName) > 256 Then Return SetError(1, 0 ,0)
    If $s_helo = "" Then $s_helo = @ComputerName

    If TCPStartup() = 0 Then Return SetError(2, 0 ,0)

    Local $s_IPAddress, $i_Count
    StringRegExp($s_SmtpServer, "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)")
    If @extended Then
        $s_IPAddress = $s_SmtpServer
    Else
        $s_IPAddress = TCPNameToIP($s_SmtpServer)
    EndIf
    If $s_IPAddress = "" Then
        TCPShutdown()
        Return SetError(3, 0 ,0)
    EndIf
    Local $v_Socket = TCPConnect($s_IPAddress, 25)
    If $v_Socket = -1 Then
        TCPShutdown()
        Return SetError(4, 0 ,0)
    EndIf

    Local $s_Send[6], $s_ReplyCode[6]   ; Return code from SMTP server indicating success
    $s_Send[0] = "HELO " & $s_helo & @CRLF
    If StringLeft($s_helo,5) = "EHLO " Then $s_Send[0] = $s_helo & @CRLF
    $s_ReplyCode[0] = "250"

    $s_Send[1] = "MAIL FROM: <" & $s_FromAddress & ">" & @CRLF
    $s_ReplyCode[1] = "250"
    $s_Send[2] = "RCPT TO: <" & $s_ToAddress & ">" & @CRLF
    $s_ReplyCode[2] = "250"
    $s_Send[3] = "DATA" & @CRLF
    $s_ReplyCode[3] = "354"

    Local $aResult = _Date_Time_GetTimeZoneInformation()
    Local $bias = -$aResult[1]/60
    Local $biasH = Int($bias)
    Local $biasM = 0
    If $biasH <> $bias Then $biasM =  Abs($bias - $biasH) * 60
    $bias =  StringFormat(" (%+.2d%.2d)", $biasH, $biasM)

    $s_Send[4] =    "From:" & $s_FromName & "<" & $s_FromAddress & ">" & @CRLF & _
            "To:" & "<" & $s_ToAddress & ">" & @CRLF & _
            "Subject:" & $s_Subject & @CRLF & _
            "Mime-Version: 1.0" & @CRLF & _
            "Date: " & _DateDayOfWeek(@WDAY, 1) & ", " & @MDAY & " " & _DateToMonth(@MON, 1) & " " & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & $bias & @CRLF & _
            "Content-Type: text/plain; charset=US-ASCII" & @CRLF & _
            @CRLF
    $s_ReplyCode[4] = ""

    $s_Send[5] = @CRLF & "." & @CRLF
    $s_ReplyCode[5] = "250"

Looking at the above section of code from that function, this is the initial part that just ensures that it can just attempt the connection to the mail server at all.

; open stmp session
    If __SmtpSend($v_Socket, $s_Send[0], $s_ReplyCode[0], $b_trace, "220", $s_first) Then Return SetError(50, 0, 0)

    ; send header
    For $i_Count = 1 To UBound($s_Send) - 2
        If __SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then Return SetError(50 + $i_Count, 0 ,0)
    Next

This part opens the smtp session and sends the header. Is this all I need to verify the mailbox exists? If the server receives the header and nothing more, does it still put mail in the receiving mailbox?


[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0