Python Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Python Examples

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

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

 

 

 

 

 

 

 

Zip Email Attachments

Download Chilkat Python 2.5 Library

Download Chilkat Python 2.6 Library

Download Chilkat Python 2.6 Library (x64)

Python script to convert email attachments to a single .zip file attachment and send.

# file: ZipAttachments.py

import chilkat 

# Python script to email with attachments contained in a .zip.
mailman = chilkat.CkMailMan()
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()
email.put_Subject("Sending email with zipped attachments from Python")
email.put_Body("This email was sent from a Python 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")

# Add attachments as in the previous Python example (EmailAttachments.py)
contentType = chilkat.CkString()
success = email.AddFileAttachment("exampleData/hamlet.xml",contentType)
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")

# You could send the email at this point in the code by calling mailman.SendEmail.
# If you did, your email would have 3 attachments: test1.txt, test2.txt, and hamlet.xml
# However, you could first call email.ZipAttachments like this:
email.ZipAttachments("myAttachments.zip");

# myAttachments.zip is the name of the attachment that will appear in the email.
# After calling ZipAttachments, your email will contain 1 attachment 
# (myAttachments.zip) and within it are three files: 
# test1.txt, test2.txt, and hamlet.xml.   

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






 

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

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