Ruby Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



Ruby
Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
Signatures
SFTP
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
HTTP Upload
XML
XMP
Zip

More Examples...
String
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
DH Key Exchange
DSA
LZW

 

 

 

 

 

 

 

Saving Email Attachments

How to save email attachments in Ruby.

Download Ruby Programming Example Scripts

# file: SaveAttachments.rb

# Ruby script to save email attachments.

require 'chilkat'

# Create an instance of the mailman object for reading POP3 email.
mailman = Chilkat::CkMailMan.new()
mailman.UnlockComponent("anything for 30-day trial")

# Create an email object and load it with a .eml file.
email = Chilkat::CkEmail.new()
email.LoadEml("testEmail.eml")

# Save all attachments to a relative subdirectory named "attachments"
# The directory is automatically created if it does not yet exist.
email.SaveAllAttachments("attachments")
# Save all attachments to an absolute directory named "/temp/attachments"
# The directory is automatically created if it does not yet exist.
email.SaveAllAttachments("/temp/attachments")

# The email.OverwriteExisting property controls whether existing files
# are overwritten if attachments have the same filename.  This property
# is true by default.  If set to false, the attachment filename(s) will
# be modified if there is a conflict.
email.put_OverwriteExisting(false)

# Attachments may also be saved individually:
numAttach = email.get_NumAttachments()
filename = Chilkat::CkString.new()
for j in 0..(numAttach-1)
	email.GetAttachmentFilename(j,filename)
	fileSize = email.GetAttachmentSize(j)
	print "Before saving: " + filename.getUtf8() + ", " + fileSize.to_s() + " bytes\n"
	# Save the Nth attachment.  Because OverwriteExisting = false, and the attachments
	# were previously saved to the same subdirectory by SaveAllAttachments, each
	# attachment filename is automatically modified to prevent ovewriting existing files.
	# The actual filename saved is available by calling GetAttachmentFilename after saving.
	email.SaveAttachedFile(j,"attachments")
	email.GetAttachmentFilename(j,filename)
	print "After saving: " + filename.getUtf8() + ", " + fileSize.to_s() + " bytes\n"
end





 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.