4D Internet Commands v16

SMTP_Attachment

Home

 
4D Internet Commands v16
SMTP_Attachment

SMTP_Attachment 


 

SMTP_Attachment ( smtp_ID ; fileName ; encodeType ; deleteOption {; attachmentID {; contentType}} ) -> Function result 
Parameter Type   Description
smtp_ID  Longint in Message reference
fileName  Text in Name of file to attach
encodeType  Integer in 0 = No encoding (sends DataFork only) ±1 = BinHex ±2 = Base64; (sends DataFork only) ±3 = AppleSingle ±4 = AppleDouble ±5 = AppleSingle AND Base64 ±6 = AppleDouble AND Base64 ±7 = UUEncode
deleteOption  Integer in 0 = Add to existing list, 1 = Replace all attachments with Filename, 2 = Remove only this attachment
attachmentID  Text in ID of attachment (HTML messages only)
contentType  Text in Value of content type to set
Function result  Integer in Error Code

The SMTP_Attachment command provides a means to attach text or binary files to your message in MIME format. This command may be called multiple times in order to attach multiple documents to one mail message. If a value greater than zero is passed to the encodeType parameter, this command will perform encoding at the time the message is sent.

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

fileName contains the name of the file you want to attach to the message. This value may be specified three different ways:

""= Display the Standard Open File dialog.
"FileName"= Looks for FileName in the same directory as the structure of the database.
"Path:FileName"= Complete path of the file including FileName.

encodeType is an Integer value indicating what type of encoding will be done on the file before it is incorporated into the message. If attaching a binary file, an encoding method must be applied capable of the proper conversion (BinHex, AppleSingle). The most common encoding method is BinHex.

If you pass positive values of encodeType the command will automatically encode the file using the specified method when the message is sent. The encoding of a file occurs at the time the SMTP_Send command is issued. If the file is large it may take some time for the SMTP_Send command to complete. Significant time may be saved in cases where the same file will be sent a number of times. In these cases it is best to encode the file one time with the IT_Encode command and then attach the resulting file to your message using the negative value of encodeType. A negative value in encodeType will not perform any additional encoding but will set the message headers to the correct encoding method of the attached file. This will inform your recipients' mail reader of the correct way to interpret your attachment.

Note: You cannot pass an array element to the encodeType parameter.

deleteOption is an optional integer parameter which specifies how to treat the attachment.

  • A value of zero will add the attachment to the current list of attachments.
  • A value of 1 will replace all attachments with the file in fileName. If fileName is a null string, all attachments will be removed.
  • A value of 2 will remove only the attachment listed in fileName from the list of attachments.

The attachmentID parameter associates the attachment with a reference defined in the message body using the HTML tag <img src=\"cid:ID\">. This means that the contents of the files, for example a picture, can be displayed within the message on the e-mail client.
This functioning is only supported with messages in HTML. Also note that the final result may vary depending on the e-mail client.

The optional contentType parameter explicitly sets the content type of the attachment file. By default, if this parameter is omitted or contains an empty string, 4DIC automatically sets the content type of the attachment file based on its extension. The following rules are applied:

ExtensionContent Type
jpg, jpegimage/jpeg
pngimage/png
gifimage/gif
pdfapplication/pdf
docapplication/msword
xlsapplication/vnd.ms-excel
pptapplication/vnd.ms-powerpoint
zipapplication/zip
gzapplication/gzip
jsonapplication/json
jsapplication/javascript
psapplication/postscript
xmlapplication/xml
htm, htmltext/html
mp3audio/mpeg
otherapplication/octet-stream

In contentType, you can pass a string defining the content type (MIME type) for the file, for example "video/mpeg". This content-type value will be set for the attachment, regardless of its extension.

Note: Pass an empty string ("") in attachmentID if you do not want to use this parameter.

Sending an HTML message with a picture included:

 $error:=SMTP_New($smtp_id)
 $error:=SMTP_Host($smtp_id;"smtp.gmail.com")
 $error:=SMTP_From($smtp_id;"henry@gmail.com")
 $error:=SMTP_ReplyTo($smtp_id;"replies@gmail.com")
 $error:=SMTP_Subject($smtp_id;"HTML Test  &  picture included")
 $error:=SMTP_To($smtp_id;"john@4d.com";1)
 $error:=SMTP_Body($smtp_id;"<html><B><I>Hello world in bold!</I></B> <img src=\"cid:myID123\">(normal text)</HTML>";4)
 $error:=SMTP_Attachment($smtp_id;"c:\\temp\\tulips.jpg";2;0;"myID123")
 $error:=SMTP_Auth($smtp_id;"henry@gmail.com";"*******")
 $error:=SMTP_Send($smtp_id;1)
 $error:=SMTP_Clear($smtp_id)

You want to declare your settings files as XML files

 $path:=Get 4D folder(Database folder)+"Settings.mySettings"
 $err:=SMTP_Attachment($smtp_id;$path;2;0;"myID123";"application/xml")



See also 

IT_Encode
SMTP_New
SMTP_Send

 
PROPERTIES 

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

 
HISTORY 

Created: 4D Internet Commands 6.5
Modified: 4D Internet Commands v14
Modified: 4D Internet Commands v14 R4

 
ARTICLE USAGE

4D Internet Commands ( 4D Internet Commands v16)