Python Examples

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

Python Examples

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

 

 

 

 

 

 

 

Send Email with Attachments

 Chilkat Python Module Downloads for Windows, Linux, and MAC OS X

Python script to send email with attachments.

# file: EmailAttachments.py

import chilkat 

# Sends email with attachments in Python.
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 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("John","john@example.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 (for whatever reason), but most users do not.
contentType = chilkat.CkString()
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");






 

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