Ruby Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Ruby
Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML Conversion
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
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
DH Key Exchange
DSA
LZW

 

 

 

 

 

 

 

message/rfc822 Attached Email Messages

Downloads for Windows/Linux and Install Instructions

Ruby source code example to extract an attached message from an email. It is often the case that when an email is forwarded, the original email is attached as a message/rfc822 sub-part contained within an outer multipart/mixed MIME type. The Chilkat Ruby email module provides methods for accessing attached messages.

# file: AttachedEmail.rb

# Forwarded emails contain the original email(s) in message/rfc822 sub-parts.
# The Chilkat Email API provides a method for extracting an attached message
# and returning it as an email object.  It is possible for an email to contain
# an attached message, which in turn contains another, etc.   There is no limitation
# on the number of possible recursive nesting levels.

require 'rubygems'
require 'chilkat'

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

# Load an email with an attached message from a .eml file.
email = Chilkat::CkEmail.new()
success = email.LoadEml("forwardedEmail.eml")
if not success
	email.SaveLastError("lastError.xml")
else
	numAttachedMsgs = email.get_NumAttachedMessages()
	
	subject = Chilkat::CkString.new()
	fromAddr = Chilkat::CkString.new()
	
	for i in 0..(numAttachedMsgs-1)
		attachedEmail = email.GetAttachedMessage(i)
		
		# Do a few things with the attached email, for demonstration purposes.
		attachedEmail.SaveEml("attachedEmail_" + i.to_s() + ".eml")
		
		attachedEmail.get_Subject(subject)
		attachedEmail.get_FromAddress(fromAddr)
		
		print "Attached Email: " + i.to_s() + "\n"
		print "    Subject: " + subject.getUtf8() + "\n"
		print "    From: " + fromAddr.getUtf8() + "\n\n"
	end	
end






 

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