OnSmtpData is called ONCE per message.
Do NOT try to save a message (oMessage.Save) in "Sub OnSMTPData(oClient, oMessage)" or you will seriously disrupt the message!
The following properties are the only ones populated at the point of OnSMTPData firing:
OnSMTPData(oClient as hMailServer.Client, oMessage as hMailServer.Message)
The built-in SMTP authentication functionality checks only the sender address to determine whether SMTP authentication is required. Often, you want to check sender address as well. The following script makes hMailServer require authentication, if the senders address contains @example.com.
VB-script:
Sub OnSMTPData(oClient, oMessage)
If (InStr(1, oMessage.FromAddress, "@example.com", 1) > 0) Then
If (oClient.Username = "") Then
Result.Message = "You must be authenticated to send from local domain."
Result.Value = 2
End If
End If
End Sub