Server Side Emails with Attachment from Container Field
If [ not IsEmpty ( EmailLog::Attachment ) ]
# Define temporary path and file variables
Set Variable [ $_tempPath ; Value: Get(TemporaryPath) ]
Set Variable [ $_fileName ; Value: GetContainerAttribute ( EmailLog::Attachment ; "filename" ) ]
Set Variable [ $_filePath ; Value: $_tempPath & $_fileName ]
# Check if the file already exists
Get File Exists [ “$_filePath” ; Target: $fileExists ]
If [ $fileExists = 1 ]
Delete File [ Target: “$_filePath” ]
End If
# Create and write to the data file
Create Data File [ “$_filePath” ; Create folders: On ]
Open Data File [ “$_filePath” ; Target: $_filePathID ]
# Writing data to the file
Write to Data File [ File ID: $_filePathID ; Data source: EmailLog::Attachment ; Write as: Base64 ]
Close Data File [ File ID: $_filePathID ]
# Prepare the email parameters
Set Variable [ $emailTo; Value: "recipient@example.com" ]
Set Variable [ $emailSubject; Value: "Email Subject" ]
Set Variable [ $emailBody; Value: "This email includes an attachment." ]
# Send the email
Send Mail [
Send via SMTP Server: "smtp.example.com" ;
From: "your-email@example.com" ;
To: $emailTo ;
Subject: $emailSubject ;
Message: $emailBody ;
Attachment: $_filePath ;
SMTP Authentication: On ;
User name: "your-username" ;
Password: "your-password"
]
# Clean up by deleting the temporary file
Delete File [ Target: “$_filePath” ]
End If