| 4D v13.2SMTP_Send | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | 
    4D v13.2
 SMTP_Send 
         | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SMTP_Send ( smtp_ID {; sessionParam} ) -> Function result | ||||||||
| Parameter | Type | Description | ||||||
| smtp_ID | Longint |   | Message reference | |||||
| sessionParam | Longint |   | 0 or omitted = Do not use SSL but switchover allowed, 1 = Use SSL, 2 = Never use SSL (switchover not allowed) | |||||
| Function result | Integer |   | 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:
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.
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));
	Product:  4D
	Theme:  IC Send Mail
	Number:  
        88989
        
        
        
	

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