Ruby Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



Ruby
Examples

Quick Start
Ruby Unicode
Ruby Byte Array
Ruby Certs
Ruby Email
Ruby Encryption
Ruby FTP
HTML-to-XML
Ruby HTTP
Ruby IMAP
Ruby MHT
Ruby MIME
Ruby S/MIME
Ruby Signatures
Ruby RSA
Ruby Socket
Ruby Spider
Ruby Tar
Ruby Upload
Ruby XML
Ruby XMP
Ruby Zip

More Examples...
String
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

Send Email with Attachments

Ruby script to send email with attachments.

Download Ruby Programming Example Scripts

# file: EmailAttachments.rb

require 'chilkat'

# Sends email with attachments in Ruby.
mailman = Chilkat::CkMailMan.new()
mailman.UnlockComponent("anything for 30-day trial")

# Set your SMTP server's hostname
mailman.put_SmtpHost("smtp.comcast.net")

# If your SMTP server requires a login, set username/password
# mailman.put_SmtpUsername("myUsername")
# mailman.put_SmtpPassword("myPassword")

# Create a simple email with attachments
email = Chilkat::CkEmail.new()
email.put_Subject("Sending email with attachments from Ruby")
email.put_Body("This email was sent from a Ruby script")
email.put_From("Chilkat Support <support@chilkatsoft.com>")

# Add a few recipients
email.AddTo("Matt","matt@chilkatsoft.com")
email.AddTo("TagTooga","admin@tagtooga.com")

# Attachments can be added from files or in-memory data.
# Returns true if the file was added successfully.  The content-type
# is returned in the 2nd argument.  This is for the benefit of programs
# that may need it, but most do not.
contentType = Chilkat::CkString.new()
success = email.AddFileAttachment("exampleData/hamlet.xml",contentType)

# You may add a text file attachment directly from a string in memory.
# AddStringAttachment2 allows for the charset encoding to be directly specified.
# AddStringAttachment automatically uses the utf-8 encoding for text file attachments.
email.AddStringAttachment("test1.txt","This string is the content of test1.txt")
email.AddStringAttachment2("test2.txt","This string is the content of test2.txt","iso-8859-1")

success = mailman.SendEmail(email)
if not success
	mailman.SaveLastError("lastError.txt");
end





 

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

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