[GB.NET.SMTP]
* NEW: Support for PLAIN and CRAM-MD5 authentications. git-svn-id: svn://localhost/gambas/trunk@7495 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
40c8517465
commit
e854439f50
2 changed files with 65 additions and 13 deletions
|
@ -18,9 +18,27 @@ Public Sub Main()
|
|||
' hClient.Add(File.Load("~/TexteDehorsilpleut.odt"), "application/vnd.oasis.opendocument.text", "Dehors il pleut.odt")
|
||||
' hClient.Add(File.Load("~/balloon.png"), "image/png", "balloon.png")
|
||||
' hClient.Send
|
||||
|
||||
|
||||
Dim hMsg As New SmtpClient
|
||||
|
||||
' Dim sChallenge As String
|
||||
' Dim sKey As String
|
||||
' Dim sCommand As String
|
||||
' Dim sResult As String
|
||||
'
|
||||
' sChallenge = "'abc'"
|
||||
' sKey = "benoit"
|
||||
'
|
||||
' sCommand = "echo -n " & Shell$(sChallenge) & " | openssl md5 -hmac " & Shell$(sKey)
|
||||
' Shell sCommand To sResult
|
||||
' Print sResult
|
||||
'
|
||||
' sCommand = "openssl md5 -hmac " & Shell$(sKey) & " << EOF\n'abc'"
|
||||
' Shell sCommand To sResult
|
||||
' Print sResult
|
||||
'
|
||||
' Return
|
||||
|
||||
hMsg.Debug = True
|
||||
hMsg.To.Add("benoit@minisini.fr")
|
||||
hMsg.Subject = "Test mail headers 5"
|
||||
|
|
|
@ -309,21 +309,55 @@ Catch
|
|||
End
|
||||
|
||||
Private Sub Authenticate()
|
||||
|
||||
Dim sData As String
|
||||
|
||||
|
||||
Dim sChallenge64, sChallenge, sKey, sCommand, sResponse, sDigestHex As String
|
||||
|
||||
If Not $sUser Then Return
|
||||
|
||||
sData = $hSession.Send("AUTH PLAIN")
|
||||
If $hSession.LastCode <> "334" Then Error.Raise("Unsupported authentication method")
|
||||
|
||||
sData = $hSession.Send(Base64$($sUser & Chr$(0) & $sUser & Chr$(0) & $sPassword), True)
|
||||
If $hSession.LastCode <> "235" Then Error.Raise("Authentication failed")
|
||||
|
||||
|
||||
' AUTH LOGIN
|
||||
$hSession.Send("AUTH LOGIN")
|
||||
If $hSession.LastCode = "334" Then
|
||||
$hSession.Send(Base64$($sUser))
|
||||
If $hSession.LastCode = "334" Then
|
||||
$hSession.Send(Base64$($sPassword))
|
||||
If $hSession.LastCode = "235" Then Return
|
||||
Endif
|
||||
Endif
|
||||
|
||||
' AUTH PLAIN
|
||||
$hSession.Send("AUTH PLAIN")
|
||||
If $hSession.LastCode <> "334" Then
|
||||
$hSession.Send("AUTH PLAIN " & Base64$($sUser & Chr$(0) & $sUser & Chr$(0) & $sPassword), True)
|
||||
Else
|
||||
$hSession.Send(Base64$($sUser & Chr$(0) & $sUser & Chr$(0) & $sPassword), True)
|
||||
Endif
|
||||
If $hSession.LastCode = "235" Then Return
|
||||
|
||||
' CRAM-MD5
|
||||
$hSession.Send("AUTH CRAM-MD5")
|
||||
'If $hSession.LastCode = "334" Then Print "LastAnswer = "; $hSession.LastAnswer
|
||||
|
||||
sChallenge64 = Split($hSession.LastAnswer, " ")[1]
|
||||
sChallenge = UnBase64(sChallenge64)
|
||||
sKey = $sPassword
|
||||
|
||||
'sCommand = "echo -n " & Shell$(sChallenge) & " | openssl md5 -hmac " & Shell$(sKey)
|
||||
sCommand = "openssl md5 -hmac " & Shell$(sKey) & " << EOF\n" & sChallenge
|
||||
Shell sCommand To sDigestHex
|
||||
|
||||
sDigestHex = Trim(Split(sDigestHex, "=")[1])
|
||||
sResponse = Base64($sUser & sDigestHex)
|
||||
|
||||
$hSession.Send(sResponse)
|
||||
If $hSession.LastCode = "235" Then Return
|
||||
|
||||
' Nothing worked?
|
||||
Error.Raise("Authentication failed")
|
||||
|
||||
Catch
|
||||
|
||||
|
||||
Error.Raise("Unable to authenticate: " & Error.Text)
|
||||
|
||||
|
||||
End
|
||||
|
||||
Private Sub SendRecipients()
|
||||
|
|
Loading…
Reference in a new issue