4D Internet Commands v15

SMTP_QuickSend

  •  
 
4D Internet Commands v15
SMTP_QuickSend

SMTP_QuickSend 


 

SMTP_QuickSend ( nomServeur ; msgDe ; msgA ; msgObjet ; message {; paramSession}{; port}{; nomUtilisateur ; motDePasse} ) -> Résultat 
Paramètre Type   Description
nomServeur  Chaîne in Nom ou adresse IP du serveur
msgDe  Texte in Adresse électronique ou Liste d'adresses
msgA  Texte in Adresse électronique ou Liste d'adresses
msgObjet  Texte in Objet du message (UTF-8 par défaut)
message  Texte in Message (UTF-8 par défaut)
paramSession  Entier long in 0 ou omis = Ne pas utiliser SSL mais bascule permise, 1 = Utiliser SSL, 2 = Ne jamais utiliser SSL (bascule non permise), 4 = Envoyer texte HTML sans SSL, 5 = Envoyer texte HTML avec SSL, 8 = Envoyer Mime HTML sans SSL/TLS, 9 = Envoyer Mime HTML avec SSL/TLS
port  Entier long in Numéro de port à utiliser
nomUtilisateur  Texte in Nom d’utilisateur pour l’authentification
motDePasse  Texte in Mot de passe pour l’authentification
Résultat  Entier in Code d'erreur

The SMTP_QuickSend command gives the users the ability to build and send a mail message with one command. In the event that you require greater control over your message, or the message is of a more sophisticated nature, the group of SMTP commands based on the SMTP_New command should be utilized.

Note: This command cannot be used in converted databases operating in "non-Unicode" mode.

hostName is the host name or IP address of the SMTP server where the message will be sent for distribution.

msgFrom is a text value containing an AddressList of one or more complete mail addresses indicating who originally sent the message. All addresses listed in the From header are visible to the recipients of the message.

msgTo contains an AddressList value of one or more complete mail addresses. The addresses identified in the msgTo header will each be sent an original copy of the message. Each recipient of the message will see any other mail addresses the message was delivered to.

subject is a text value concisely describing the topic covered in detail by the message body.

Note: By default, the subject and body of the message are encoded in UTF-8, which ensures that the characters sent will be interpreted correctly by almost all of the e-mail clients. If you want to use a specific character set, refer to the SMTP_SetPrefs and SMTP_Charset commands.

message is a text value containing the body of the mail message. For historical reasons, the size of the message is restricted to 32 KB.

The optional sessionParam parameter sets the message format (standard text, HTML or Mime HTML) and the activation mode of the SSL protocol for the connection:

  • If you pass 0 or omit this parameter, the message will be formatted as text and 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 formatted as text and sent in SSL (synchronous mode),
  • If you pass 2, the message will be formatted as text and sent in standard mode but without supporting updating to SSL/TLS,
  • If you pass 4, the message will be formatted as HTML and sent in standard mode,
  • If you pass 5, the message will be formatted as HTML and sent in SSL/TLS mode,
  • If you pass 8, the message will be formatted as Mime HTML and sent in standard mode,
  • If you pass 9, the message will be formatted as Mime HTML and sent in SSL/TLS mode.
    Note: Mime HTML (.mht or .mhtml file extension) is a Web page archive format that can merge the HTML code as well as external resources such as images into a single document. It is supported by several browsers as well as MS Word, for example. Since this format is supported by 4D Write Pro areas, you will easily be able to save and send 4D Write Pro areas by mail including all their resources.

Note that these values correspond to usual combinations, however the sessionParam parameter is a actually a bit field and allows any custom combinations if you use Bitwise Operators:

Bit numberFormat used if bit is 1
0Use SSL or use default behavior, connect in clear, then upgrade to SSL if possible.
1Never upgrade, stay in non-encrypted mode even if upgrade is possible. Bit is ignored if SSL (bit-0) is selected.
2Message body is HTML, set the header accordingly.
3MHTML message, bit-2 (HTML) is ignored. User is responsible to set everything up, except "To", "From", "Date", and "Subject"

The optional port parameter specifies the SMTP port number to use for connection with the server. The most frequently used values are:

  • 25 = standard non-secure STMP port (default port when parameter is omitted)
  • 465 = SMTPS (SSL/TLS) port
  • 587 = standard (but secure) SMTP port; pass this port for connections with a MS Exchange server (explicit mode).

The optional userName and password parameters are used to authenticate the sender with the mail server. These parameters must be passed together. Note that the most secure authentication mode supported by the server will be used (as with the default mode of the SMTP_Auth command).

Here is an example of use of this command:

 $Host:="www.4d.com"
 $ToAddress:="adupont@4d.fr"
 $FromAddress:="jsmith@4d.com"
 $Subject:="Sales Report"
 $Message:="Can you send me the sales report for January 2009? Thanks."
 $Error:=SMTP_QuickSend($Host;$FromAddress;$ToAddress;$Subject;$Message;1)
 If($Error#0)
    ALERT("Error: SMTP_QuickSend"+Char(13)+IT_ErrorText($Error))
 End If

Example for using the command to send a secure message through a MS Exchange server:

 $ServerName:="exchange.4d.com"
 $MsgTo:="adupont@gmail.com"
 $MsgFrom:="a.user@4d.com"
 $Subject:="Test message"
 $Message:="This is a test for sending a message in secure mode. Please do not reply."
 $Error:=SMTP_QuickSend($ServerName;$MsgFrom;$MsgTo;$Subject;$Message;0;587;"a.user";"@!password@!")

Sending a message in HTML with SSL/TLS:

 $Host:="smtp.gmail.com"
 $ToAddress:="john@4d.com"
 $FromAddress:="harry@gmail.com"
 $Subject:="Message HTML"
 $Message:="Let’s meet at <b>Joe’s Coffee Shop</b>!"
 $Param:=5 //HTML with SSL
 $Port:=465 //SSL port of gmail
 $User:="harry@gmail.com"
 $Password:="xyz&@!&@"
 $Error:=SMTP_QuickSend($Host;$FromAddress;$ToAddress;$Subject;$Message;$Param;$Port;$User;$Password)

You saved a .mht document on your disk and want to send it by email. To do this, you can write:

 $Message:=Document to text("c:\\documents\\invitation.mht")
 $Host:="smtp.gmail.com"
 $ToAddress:="john@4d.com"
 $FromAddress:="harry@gmail.com"
 $Subject:="Let's party"
 $Param:=9 //MHTML with SSL
 $Port:=465 //SSL port of gmail
 $User:="harry@gmail.com"
 $Password:="xyz&@!&@"
 $Error:=SMTP_QuickSend($Host;$FromAddress;$ToAddress;$Subject;$Message;$Param;$Port;$User;$Password)



Voir aussi  

SMTP_Charset
SMTP_New
SMTP_SetPrefs