Tcl
Tcl
Add Email Attachment from FTP
Downloads (into memory) a file from an FTP server and adds it as an attachment to an email.Note: This example requires Chilkat v9.5.0.63 or later.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Note: This example requires Chilkat v9.5.0.63 or later.
# This example assumes Chilkat Ftp2 to have been previously unlocked.
# See Unlock Ftp2 for sample code.
set ftp [new_CkFtp2]
CkFtp2_put_Hostname $ftp "www.my-ftp-server.com"
CkFtp2_put_Username $ftp "mFtpLogin"
CkFtp2_put_Password $ftp "myFtpPassword"
# Connect to the FTP server.
set success [CkFtp2_ConnectOnly $ftp]
if {$success != 1} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
# Authenticate with the FTP server.
set success [CkFtp2_LoginAfterConnectOnly $ftp]
if {$success != 1} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
# Move to the remove directory where our file is located.
set success [CkFtp2_ChangeRemoteDir $ftp "qa_data"]
if {$success == 1} then {
set success [CkFtp2_ChangeRemoteDir $ftp "pdf"]
}
if {$success != 1} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
# Download...
set pdfData [new_CkBinData]
set success [CkFtp2_GetFileBd $ftp "fishing.pdf" $pdfData]
if {$success != 1} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
delete_CkBinData $pdfData
exit
}
CkFtp2_Disconnect $ftp
# Create an email object, and add the PDF as an attachment.
set email [new_CkEmail]
CkEmail_put_Subject $email "Test with PDF attachment."
CkEmail_put_Body $email "This is a plain-text body.."
# Add the PDF attachment. (This method call requires Chilkat v9.5.0.63 or later)
set success [CkEmail_AddAttachmentBd $email "fishing.pdf" $pdfData "application/pdf"]
if {$success != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkFtp2 $ftp
delete_CkBinData $pdfData
delete_CkEmail $email
exit
}
# Save the email and examine with a text editor to see the PDF attachment is present..
CkEmail_SaveEml $email "qa_output/out.eml"
puts "Success."
delete_CkFtp2 $ftp
delete_CkBinData $pdfData
delete_CkEmail $email