OnSMTPData

Overview

OnSmtpData is called ONCE per message.

The following properties are the only ones populated at the point of OnSMTPData firing:

  • oMessage.Charset eg, utf-8
  • oMessage.Filename eg, e:\hMailData\{88ECA44E-D65A-4C8C-9797-EA1C3639D723}.eml
  • oMessage.FromAddress eg, user@domain.com
  • oMessage.recipients.item(j).address eg, touser@domain.com

Signature

OnSMTPData(oClient as hMailServer.Client, oMessage as hMailServer.Message)

Result values

  • 0 - hMailServer accepts the message
  • 1 - hMailServer rejects the message with the error 542 Rejected
  • 2 - hMailServer rejects the message with a script-defined error.

Examples

Require authentication for local senders

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

 

Search documentation