4D Internet Commands v16

SMTP_Send

Home

 
4D Internet Commands v16
SMTP_Send

SMTP_Send 


 

SMTP_Send ( smtp_ID {; sessionParam} ) -> Function result 
Parameter Type   Description
smtp_ID  Longint in Message reference
sessionParam  Longint in 0 or omitted = Do not use SSL but switchover allowed, 1 = Use SSL, 2 = Never use SSL (switchover not allowed)
Function result  Integer in Error Code

The SMTP_Send command sends the message referenced by smtp_ID but does not clear the data from memory.

smtp_ID is the long integer reference to the mail message created with the SMTP_New command.

The optional sessionParam parameter sets the activation mode of the SSL protocol for the connection:

  • If you pass 0 or omit this parameter, the message will be sent in standard, non-secure mode. If the server proposes an update to SSL/TLS after authentication, the switchover is performed automatically (SSL/TLS operation in explicit mode).
  • If you pass 1, the message will be sent in SSL (synchronous mode),
  • If you pass 2, the message will be sent in standard mode but without supporting updating to SSL/TLS.

Beginning with version 13.2, 4D Internet Commands supports STARTTLS connections in explicit mode. This means that the connection is first made in standard mode and then "updated" to SSL/TLS after the authentication phase. Refer to example 2 for an illustration of this mechanism.

  • The initial connection must be made on a non-SSL/TLS port that is not the default port (25). You need to call the IT_SetPort command before SMTP_Send in order to designate the port used for the initial SMTP connection. For a connection to a MS Exchange server, you must use port 587.
  • The connection must be authenticated so you have to call the SMTP_Auth command. Only the LOGIN authentication mode is supported by 4D Internet Commands to communicate with a MS Exchange server. You can either pass this mode, or leave the default mode (in this case, the most secure mode available on the server is used):
     $error:=SMTP_Auth($smtp_id;"user.name";"password";2) // OK for LOGIN mode
     v$error:=SMTP_Auth($smtp_id;"user.name";"password") // OK for LOGIN mode set by the server

In this example a message is created and the static elements are defined outside the scope of the 'for' loop. Then, for each record in the [People] table, the message is customized and sent.

 $error:=SMTP_New($smtp_id)
 $error:=SMTP_Host($smtp_id;"wkrp.com")
 $error:=SMTP_From($smtp_id;"herb_tarlick@wkrp.com")
 $error:=SMTP_ReplyTo($smtp_id;"bigguy@wkrp.com")
 $error:=SMTP_Subject($smtp_id;"Discounts on Ad Space!")
 FIRST RECORD([People])
 For($i;1;Records in selection([People]))
    If([People]Sales2Date>100000)
       $Body:=◊BigDiscText
    Else
       $Body:=◊SmlDiscText
    End if
    $Body:=Replace string($BoilerPlate;"<Salutation>";[People]Firstname)
    $error:=SMTP_To($smtp_id;[People]Email;1) `Replace the "To" header with new value
    $error:=SMTP_Body($smtp_id;$Body)
    $error:=SMTP_Send($smtp_id)
    NEXT RECORD([People])
 End for
 $error:=SMTP_Clear($smtp_id)

This example sends a test message using an Exchange server in STARTTLS:

 $error:=SMTP_New($smtp_id)
 $error:=SMTP_Host($smtp_id;"exchange.4d.com")
 $error:=SMTP_From($smtp_id;"username@4d.com")
 $error:=SMTP_ReplyTo($smtp_id;"username@4d.com")
 $error:=SMTP_Subject($smtp_id;"Message test")
 $error:=SMTP_Auth($smtp_id;"username";"!%@password") //use valid IDs
 $Body:="This is a test for messages sent through the Exchange, please do not reply"
 $error:=IT_SetPort(2;587) //standard STMP mode, port 587 for Exchange
 $error:=SMTP_To($smtp_id;"recipient@gmail.com")
 $error:=SMTP_Body($smtp_id;$Body)
 $error:=SMTP_Send($smtp_id;0) //Send in 'upgradable' mode
 ALERT(String($error));



See also 

SMTP_New

 
PROPERTIES 

Product: 4D Internet Commands
Theme: IC Send Mail
Number: 88989

 
HISTORY 

Created: 4D Internet Commands 6.5
Modified: 4D Internet Commands v12.1
Modified: 4D v13.2

 
ARTICLE USAGE

4D Internet Commands ( 4D Internet Commands v16)