Authenticate event is fired when user tries to
authenticate himself to the server. At this point you
should check if provided Username
and Password are valid - and set
Action property to Allow
or Deny, depending if his credentials are correct
or not. If you setup Authentication
property so it is required, user will not be able to send
the message (not even to attempt to send it) unless you
return Action = Allow from
this event.
In authentication types (other than AuthCramMD5), Username and Password will
contain plaintext username/password you need to check
against ones stored in your database - so allowing access
is pretty much straightforward:
Private Sub wodSmtpServer1_Authenticate(ByVal User As
WODSMTPSERVERCOMLib.ISmtpUser, ByVal Username As
String, ByVal Password As
String, ByVal AuthMethod As
WODSMTPSERVERCOMLib.SmtpAuthentications, Action
As
WODSMTPSERVERCOMLib.SmtpActions)
If AuthMethod <> AuthCramMD5 Then
If Login = "joe"
And Password = "joesecretpassword" Then Action = Allow
End If
End Sub
AuthCramMD5 authentication type never exposes secret
password by the client. Client sends calculate MD5 digest
value (which is stored in Password
property), and you must do the same using CalcCramMD5
method. If these two results match - user supplied correct
username/password.
You can use this event like this (assuming you will only
allow user joe with password
joesecretpassword to
authenticate):
Private Sub wodSmtpServer1_Authenticate(ByVal User As
WODSMTPSERVERCOMLib.ISmtpUser, ByVal Username As
String, ByVal Password As
String, ByVal AuthMethod As
WODSMTPSERVERCOMLib.SmtpAuthentications, Action
As
WODSMTPSERVERCOMLib.SmtpActions)
Select Case
AuthMethod
Case AuthLogin
Case AuthPlain
If Username = "joe" And
Password = "joesecretpassword" Then Action = Allow
Case AuthCramMD5
If Username = "joe" And
User.CalcCramMD5("joesecretpassword") = Password
Then Action = Allow
End Select
End Sub