By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,136 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,136 IT Pros & Developers. It's quick & easy.

Python To Send Emails Via Outlook Express

P: n/a
ian
Hi,
I'm a newbie (oh no I can here you say.... another one...)

How can I get Python to send emails using the default windows email
client (eg outlook express)?

I thought I could just do the following

import win32com.client

s = win32com.client.Dispatch('CDO.Message')
s.From = "ia*@kirbyfooty.com"
s.To = "so*****@yahoo.com"
s.Subject = "The subject"
s.Send

.... but nothing happens.

What am I doing wrong? Does anyone have some sample code to share with
me please?

Thank you!

Ian Cook

(freeware author of Kirby Alarm And Task Scheduler www.kirbyfooty.com)

Jul 18 '05 #1
Share this Question
Share on Google+
40 Replies


P: n/a
>>>>> "ian" == ian <ia*@kirbyfooty.com> writes:
import win32com.client s = win32com.client.Dispatch('CDO.Message')
s.From = "ia*@kirbyfooty.com"
s.To = "so*****@yahoo.com"
s.Subject = "The subject"
s.Send ... but nothing happens. What am I doing wrong? Does anyone have some sample code to share with
me please?


Try s.Send().

Ganesan
Jul 18 '05 #2

P: n/a
ian
Hi Ganesan
I tried changing s.Send to s.Send(). It now comes up with an exception
error..

The details are below.

Ian

Traceback (most recent call last):
File
"C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py" ,
line 307, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=0)
File
"C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
File
"C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
line 595, in run
exec cmd in globals, locals
File "D:\MyPython\emailtest.py", line 7, in ?
s.Send()
File
"C:\Python23\lib\site-packages\win32com\gen_py\CD000000-8B95-11D1-82DB-00C04FB1625Dx0x1x0.py",
line 686, in Send
return self._oleobj_.InvokeTypes(158, LCID, 1, (24, 0), (),)
com_error: (-2147352567, 'Exception occurred.', (0, None, 'The server
rejected one or more recipient addresses. The server response was: 554
<iw****@yahoo.com>: Relay access denied\r\n', None, 0, -2147220977),
None)

Jul 18 '05 #3

P: n/a
<ia*@kirbyfooty.com> wrote:
I tried changing s.Send to s.Send(). It now comes up with an exception
error.. com_error: (-2147352567, 'Exception occurred.', (0, None, 'The server
rejected one or more recipient addresses. The server response was: 554
<iw****@yahoo.com>: Relay access denied\r\n', None, 0, -2147220977),
None)


sure looks like you managed to talk to the mail program, but your mail
server thinks you're trying to send faked mails. your local mail admins
can probably help you sort this one out.

(googling for "Relay access denied" could also help)

</F>

Jul 18 '05 #4

P: n/a
ian
Thanks Fredrik,
That was my first impression too.

But all I want to do is use Python to instruct Outlook Express to send
an email.
That way the user would not have to do any setting up etc of the mail
server properties etc and Outlook Express will magage all the
connection side of things.

I have seen other python scripts that will talk to Excel etc but so far
(despite a lot of searching) I cannot see how Python can talk to
Outlook Express.

I know I can do this in Clarion by accessing MapiSendEmail but because
I'm new to Python I don't know how to do it in Python. I'm really
impressed with the power of Python. It seems just about anything you
can think of is there already so I know th eanswer is out there
somewhere!

Can this be done using Python? Does anyone have a sample script please?
Pretty please?? <grin>

Ian

Jul 18 '05 #5

P: n/a
ia*@kirbyfooty.com wrote:
Hi Ganesan
I tried changing s.Send to s.Send(). It now comes up with an exception
error..

The details are below.


Looks like the COM part works, but sending mail has an error from the
SMTP host. But, slightly off topic, FYI, Python can send email directly
with the email and snmplib modules.
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
Keith Dart <kd***@kdart.com>
public key: ID: F3D288E4
================================================== ===================
Jul 18 '05 #6

P: n/a
ia*@kirbyfooty.com wrote:
Thanks Fredrik,
That was my first impression too.

But all I want to do is use Python to instruct Outlook Express to send
an email.

Which you did! From the look of the traceback.

But your mailserver is configured in such a way that you cannot send
mail from your machine using those email adresse, or you don't log on
with the correct credentials.
--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
Jul 18 '05 #7

P: n/a
<ia*@kirbyfooty.com> wrote:
But all I want to do is use Python to instruct Outlook Express to send
an email.


and you succeeded -- the error message you saw came from the mail server, not
outlook itself. your problem is that the server didn't like the mail you sent; checking
the server configuration (or just the server logs) can help you figure out why.

have you tried different From/To settings, btw?

</F>

Jul 18 '05 #8

P: n/a
ian
Hi Keith
Thanks for your reply.

I am aware of the smtplib module and it works very well! (refer script
below)

The problem is that I have a developed a freeware application called
Kirby Alarm And Task Scheduler (see www.kirbyfooty.com).
The program can pop up a note, run a program, play a sound, or send an
email at whatever intervals the user wants..
When it comes to sending emails the user has the option of sending them
via smtp, or via there email client (eg outlook express). I prefer the
send method as this makes setting up the email parameters a lot easier
for the user.
As the program is used by over 16,000 people around the world I don't
want to complicate things by asking them to enter the mail server
properties.

Because Python is so powerful I want to develop a suite of applications
in Python that Kirby Alarm can run.
Things like FTP, Backup, Speech etc would be excellent
There has to be a way for Python to send emails via Outlook Express....

Kind regards
Ian

PS Here is the working script for sending emails via SMTP..

-----------------------------------------------------------------------------------------------------------------

# Import smtplib for the actual sending function
import os
import sys
import smtplib
import mimetypes
from email.Encoders import encode_base64
from email.MIMEAudio import MIMEAudio
from email.MIMEBase import MIMEBase
from email.MIMEImage import MIMEImage
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
FROM = 'i...@kirbyfooty.com'
TO = 'i...@cgbs.com.au;i...@yahoo.com'
SUBJECT = 'This is the subject'
MSGBODY = 'This the body of the message '
ATTACHSTR =
'c:/ian.txt;c:/c55/footytip/2003finalresults.txt;c:/snap.jpg'
MAILSERVER = 'insert mail server'
port = 25
username = 'insert username'
password = 'insert password'

# trim the strings of any leading or trailing spaces
FROM = FROM.strip()
TO = TO.strip()
SUBJECT = SUBJECT.strip()
MSGBODY = MSGBODY.strip()
ATTACHSTR = ATTACHSTR.strip()
MAILSERVER = MAILSERVER.strip()
username = username.strip()
password = password.strip()

# function to attach files
def getAttachment(path, filename):
ctype, encoding = mimetypes.guess_type(path)
if ctype is None or encoding is not None:
ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
fp = open(path, 'rb')
if maintype == 'text':
attach = MIMEText(fp.read(),_subtype=subtype)
elif maintype == 'message':
attach = email.message_from_file(fp)
elif maintype == 'image':
attach = MIMEImage(fp.read(),_subtype=subtype)
elif maintype == 'audio':
attach = MIMEAudio(fp.read(),_subtype=subtype)
else:
print maintype, subtype
attach = MIMEBase(maintype, subtype)
attach.set_payload(fp.read())
encode_base64(attach)
fp.close
attach.add_header('Content-Disposition', 'attachment',
filename=filename)
return attach

#Connect to server
print 'Connecting to mail server ', MAILSERVER
try:
s = smtplib.SMTP(MAILSERVER,port)
#s.set_debuglevel(1)
except:
print 'ERROR: Unable to connect to mail server', MAILSERVER
sys.exit(1)

#login to server
if password <> '':
print 'Logging into mail erver'
try:
s.login(username,password)
except:
print 'ERROR: Unable to login to mail server', MAILSERVER
print 'Please recheck your password'
sys.exit(1)

# get list of email addresses to send to
ToList = TO.split(';')
print 'Sending email to ', ToList

# set up email parameters
msg = MIMEMultipart()
msg['From'] = FROM
msg['To'] = TO
msg['Subject'] = SUBJECT
msg.attach(MIMEText(MSGBODY))
# get list of file attachments
AttachList = ATTACHSTR.split(';')
for file in AttachList:
try:
attach = getAttachment(file,os.path.basename(file))
msg.attach(attach)
except:
print 'Error attaching ',file
pass
# send email
s.sendmail(FROM, ToList, msg.as_string())
s.quit()
s.close()

print 'done'
-----------------------------------------------------------------------------------------

Jul 18 '05 #9

P: n/a
ian
Hi Fredrik,
Thank you for the suggestion.

I tried different from/to settings and guess what? The mail came thru.

The script is now..
import win32com.client

s = win32com.client.Dispatch('CDO.Message')
s.From = "ia*@cgbs.com.au" (was
"ia*@kirbyfooty.com")
s.To = "ia*@kirbyfooty.com" (was
"so*****@yahoo.com")
s.Subject = "The subject"
s.Send()
My problem is thought, the message is still not being sent via Outlook
Express.
What am I missing?
Thanks again for your help so far!!

Kind regards
Ian

Jul 18 '05 #10

P: n/a
>>>>> "ian" == ian <ia*@kirbyfooty.com> writes:
But all I want to do is use Python to instruct Outlook Express to send an
email. That way the user would not have to do any setting up etc of the
mail server properties etc and Outlook Express will magage all the
connection side of things.


Are you sure CDO.Message uses OE configuration to send mail? The examples of
CDO.Message usage that I see on the net appear to explicitly load some
configuration. Try this for example,

cdoSourceOutlookExpress = 2
s.Configuration.Load(cdoSourceOutlookExpress)

before s.Send(). It looks like by default CDO.Message() will use the local
IIS "Virtual SMTP Server" which refuses to relay by default.

Ganesan
Jul 18 '05 #11

P: n/a
ian
Hi Ganesan

Wow, I'm REALLY impressed with the high level of support in this forum.
(Another great reason to continue learning Python <grin>

I tried what you suggested.
After trying a different from/to address the message is sent. But it is
NOT sent via Outlook Express.

I would appreciate any other suggestions.

Thanks in advance
The script is now..

import win32com.client

s = win32com.client.Dispatch('CDO.Message')
s.From = "ia*@cgbs.com.au"
s.To = "ia*@kirbyfooty.com"
s.Subject = "The subject"
cdoSourceOutlookExpress = 2
s.Configuration.Load(cdoSourceOutlookExpress)
s.Send()

Jul 18 '05 #12

P: n/a
>>>>> "ian" == ian <ia*@kirbyfooty.com> writes:
Hi Ganesan
Wow, I'm REALLY impressed with the high level of support in this forum.
(Another great reason to continue learning Python <grin>
Well, I am a Linux guy myself. I experimented with win32com a bit a couple
of weeks back, so I am trying my ideas on you ;-).
I tried what you suggested. After trying a different from/to address the
message is sent. But it is NOT sent via Outlook Express.


s.Configuration.Load(cdoSourceOutlookExpress) only loads the OutlookExpress
configuration. It does not use Outlook Express to send. I am surprised why
your original from and to address settings didn't work after calling the
Load() method.

I did some more reading. Unlike Outlook which you can automate by getting
the application object using CreateObject("Outlook.Application") and
automate it, Outlook Express is not a COM server.

Ganesan

Jul 18 '05 #13

P: n/a
ia*@kirbyfooty.com wrote:
Hi Fredrik,
Thank you for the suggestion.

I tried different from/to settings and guess what? The mail came thru.

The script is now..
import win32com.client

s = win32com.client.Dispatch('CDO.Message')
s.From = "ia*@cgbs.com.au" (was
"ia*@kirbyfooty.com")
s.To = "ia*@kirbyfooty.com" (was
"so*****@yahoo.com")
s.Subject = "The subject"
s.Send()
My problem is thought, the message is still not being sent via Outlook
Express.
What am I missing?
Thanks again for your help so far!!

Kind regards
Ian

Unfortunately Outlook Express isn't programmable in the same way as
Outlook. I used to use it because this property gave it a certain degree
of immunity from macro viruses (back in the days when Outlook came
configured to open any Office document it came across).

About the next you can do is to add your email address as a Cc and then
file the messages when you receive them, I suspect.

Why the insistence on using Outlook Express, is you don;t mind me asking?

regards
Steve
(who almost always uses smtplib)
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #14

P: n/a
ian
Hi Steve,
Why the insistence on using Outlook Express, is you don;t mind me

asking?
Good question.
The problem is that I have a developed a freeware application called
Kirby Alarm And Task Scheduler (see www.kirbyfooty.com).
The program can pop up a note, run a program, play a sound, or send an
email at whatever intervals the user wants..

When it comes to sending emails the user has the option of sending them
via smtp, or via there email client (eg outlook express).
I prefer the send method as this makes setting up the email parameters
a lot easier for the user.
As the program is used by over 16,000 people around the world I don't
want to complicate things by asking them to enter the mail server
properties.
I have written Kirby Alarm in Clarion. It can currently send the email
via outlook express by calling MapiSendMail.

I wanted to do the same thing in Python so I can build up a suite of
useful utilities and therefore try an keep the program size relatively
small.

Ian

Jul 18 '05 #15

P: n/a
ia*@kirbyfooty.com wrote:
Hi Steve, When it comes to sending emails the user has the option of sending them
via smtp, or via there email client (eg outlook express).
I prefer the send method as this makes setting up the email parameters
a lot easier for the user.

If Outlook Express cannot be automated through COM, you are in abind.
Maybe you should shange your tactics.

What about just fetching the settings from the client?

That way the send function will be the same, and you can control it. But
the server settings could be fetched from the different clients.

It is probably much simpler to find those than it is to use them as the
sender.

Most email clients can fetch the settings from other mail clients, so
it's been done before.

--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
Jul 18 '05 #16

P: n/a
ian
Hi Max,
Thanks for the suggestion. I'm always open to new ideas.

Can you please tell me how to retrieve the default account settings
from Outlook Express?

Ian

Jul 18 '05 #17

P: n/a
>>>>> "ian" == ian <ia*@kirbyfooty.com> writes:
Hi Max,
Thanks for the suggestion. I'm always open to new ideas. Can you please tell me how to retrieve the default account settings
from Outlook Express?


s.Configuration.Load(2) is supposed to do exactly that. I have no clue
why that didn't work for you :-(.

Ganesan
Jul 18 '05 #18

P: n/a
ian
Hi Ganesan,
I'm on the verge of giving up <sigh>
I don't suppose you could write a small script to send the email for me
via the default windows email client. I will then try running your
script and my end to see if it works ok.
I may have missed something and would really appreciate your help.
Thanks in advance
Ian

Jul 18 '05 #19

P: n/a
>>>>> "ian" == ian <ia*@kirbyfooty.com> writes:
Hi Ganesan,
I'm on the verge of giving up <sigh>
I don't suppose you could write a small script to send the email for me
via the default windows email client.
I can see no easy way to do this. Though you can access the default mail
client using a registry key (I don't have enough win32 programming
experience to do this), there is no guarantee that the email client is a COM
server. Even Outlook Express is not a COM server. What if the user has
configured Eudora or something like that?

The best we can do is use Outlook Express settings and send the mail.
I will then try running your script and my end to see if it works ok. I
may have missed something and would really appreciate your help.


The final script that you pasted:

=====
import win32com.client

s = win32com.client.Dispatch('CDO.Message')
s.From = "ia*@cgbs.com.au"
s.To = "ia*@kirbyfooty.com"
s.Subject = "The subject"
cdoSourceOutlookExpress = 2
s.Configuration.Load(cdoSourceOutlookExpress)
s.Send()
=====

works fine for me. According to CDO.Message documentation, if IIS is
installed that configuration will be used by default, followed by OE
configuration. I don't have IIS installed, so the script picked up the OE
configuration automatically for me. Here's a variation of the above
script.

======
import win32com.client

s = win32com.client.Dispatch('CDO.Message')
c = win32com.client.Dispatch('CDO.Configuration')
cdoSourceOutlookExpress = 2
c.Load(cdoSourceOutlookExpress)
s.Configuration = c
s.From = "ia*@cgbs.com.au"
s.To = "ia*@kirbyfooty.com"
s.Subject = "The subject"

s.Send()
======

If that doesn't help, I give up :-(.

Ganesan
Jul 18 '05 #20

P: n/a
ian
Heavy sigh... <grin>

======
This script WILL send the email
import win32com.client
s = win32com.client.Dispatch('CDO.Message')
c = win32com.client.Dispatch('CDO.Configuration')
cdoSourceOutlookExpress = 2
c.Load(cdoSourceOutlookExpress)
s.Configuration = c
s.From = "i...@cgbs.com.au"
s.To = "i...@kirbyfooty.com"
s.Subject = "The subject"
s.Send()
======
======
But if a change the TO email address to a yahoo address the server
rejects it
import win32com.client
s = win32com.client.Dispatch('CDO.Message')
c = win32com.client.Dispatch('CDO.Configuration')
cdoSourceOutlookExpress = 2
c.Load(cdoSourceOutlookExpress)
s.Configuration = c
s.From = "i...@cgbs.com.au"
s.To = "iw****@yahoo.com"
s.Subject = "The subject"
s.Send()
======

It's official. I have given up sending emails any other way but via
smtp.

Jul 18 '05 #21

P: n/a
Steve Holden <st***@holdenweb.com> writes:
ia*@kirbyfooty.com wrote:
Hi Fredrik,
Thank you for the suggestion.
I tried different from/to settings and guess what? The mail came
thru.
The script is now..
import win32com.client
s = win32com.client.Dispatch('CDO.Message')
s.From = "ia*@cgbs.com.au" (was
"ia*@kirbyfooty.com")
s.To = "ia*@kirbyfooty.com" (was
"so*****@yahoo.com")
s.Subject = "The subject"
s.Send()
My problem is thought, the message is still not being sent via
Outlook
Express.
What am I missing?
Thanks again for your help so far!!
Kind regards
Ian

Unfortunately Outlook Express isn't programmable in the same way as
Outlook. I used to use it because this property gave it a certain
degree of immunity from macro viruses (back in the days when Outlook
came configured to open any Office document it came across).

Outlook Express can be accessed through the Simple Mapi interface -
at least the version on Win98 can. I have a program that reads
and deletes messages from the new mail folder. So I would imaging
mail can be also sent through Outlook Express using Simple Mapi,
but I have not tried it. I have also not tried using Simple Mapi
under Python, only VC++. But a quick test shows I can access
MAPI32.DLL use the ctypes package:

import ctypes
mapi = ctypes.windll.mapi32
MAPILogon = mapi.MAPILogon
....

It is messy though.

Lenard Lindstrom
<le***@telus.net>

Jul 18 '05 #22

P: n/a
ian
That sound really promising. Is there any chance you could forward me a
copy of the script. I'm still very new to Python and it would help me a
lot.
Thanks again

Ian

Jul 18 '05 #23

P: n/a
ia*@kirbyfooty.com writes:
That sound really promising. Is there any chance you could forward me a
copy of the script. I'm still very new to Python and it would help me a
lot.
Thanks again

Ian


This is a simple example I have put together:

=============== SimpleMAPI.py ======================
# module SimpleMAPI

from ctypes import *

FLAGS = c_ulong
LHANDLE = c_ulong
LPLHANDLE = POINTER(LHANDLE)

# Return codes
SUCCESS_SUCCESS = 0
# Recipient class
MAPI_ORIG = 0
MAPI_TO = 1

NULL = c_void_p(None)

class MapiRecipDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('ulRecipClass', c_ulong),
('lpszName', c_char_p),
('lpszAddress', c_char_p),
('ulEIDSize', c_ulong),
('lpEntryID', c_void_p),
]
lpMapiRecipDesc = POINTER(MapiRecipDesc)

class MapiFileDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('flFlags', c_ulong),
('nPosition', c_ulong),
('lpszPathName', c_char_p),
('lpszFileName', c_char_p),
('lpFileType', c_void_p),
]
lpMapiFileDesc = POINTER(MapiFileDesc)

class MapiMessage(Structure):
_fields_ = [('ulReserved', c_ulong),
('lpszSubject', c_char_p),
('lpszNoteText', c_char_p),
('lpszMessageType', c_char_p),
('lpszDateReceived', c_char_p),
('lpszConversationID', c_char_p),
('flFlags', FLAGS),
('lpOriginator', lpMapiRecipDesc), # ignored?
('nRecipCount', c_ulong),
('lpRecips', lpMapiRecipDesc),
('nFileCount', c_ulong),
('lpFiles', lpMapiFileDesc),
]
lpMapiMessage = POINTER(MapiMessage)

MAPI = windll.mapi32

MAPISendMail=MAPI.MAPISendMail
MAPISendMail.restype = c_ulong # Error code
MAPISendMail.argtypes = (LHANDLE, # lhSession
c_ulong, # ulUIParam
lpMapiMessage, # lpMessage
FLAGS, # lpFlags
c_ulong, # ulReserved
)

def SendMail(recipient, subject, body):
"""Post an e-mail message using Simple MAPI

recipient - string: address to send to
subject - string: subject header
body - string: message text
"""

recip = MapiRecipDesc(0, MAPI_TO, None, recipient, 0, None)
msg = MapiMessage(0, subject, body, None, None, None, 0,
cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
0, cast(NULL, lpMapiFileDesc))
rc = MAPISendMail(0, 0, byref(msg), 0, 0)
if rc != SUCCESS_SUCCESS:
raise WindowsError, "MAPI error %i" % rc
================= Example usage =========================
import SimpleMAPI
SimpleMAPI.SendMail("so*****@somewhere.com",
"The subject line"
"This is the message content.\n")
Lenard Lindstrom
<le***@telus.net>

Jul 18 '05 #24

P: n/a
ian
Hi Lenard,
Absolutely fantastic!!
That worked like a charm.
Now onto adapting it to send attachments.

Thanks again

Ian

Jul 18 '05 #25

P: n/a
ian
Hi Lenard,
Absolutely fantastic!!
That worked like a charm.
Now onto adapting it to send attachments.

Thanks again

Ian

Jul 18 '05 #26

P: n/a
ia*@kirbyfooty.com writes:
Hi Lenard,
Absolutely fantastic!!
That worked like a charm.
Now onto adapting it to send attachments.

Glad to be of help.

Lenard Lindstrom
Jul 18 '05 #27

P: n/a
ian
Hi Lenard,

As the risk of severely embarassing myself can I ask for your help one
more time.
I have tried changing your script to include attachments, but guess
what, (and this should come as no suprise) I can't do it.
So....
Here is my feeble attempt at changing the script..
----------------------------------------------------------------------------------------
import os
from ctypes import *

FLAGS = c_ulong
LHANDLE = c_ulong
LPLHANDLE = POINTER(LHANDLE)
# Return codes
SUCCESS_SUCCESS = 0
# Recipient class
MAPI_ORIG = 0
MAPI_TO = 1
NULL = c_void_p(None)
class MapiRecipDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('ulRecipClass', c_ulong),
('lpszName', c_char_p),
('lpszAddress', c_char_p),
('ulEIDSize', c_ulong),
('lpEntryID', c_void_p),
]
lpMapiRecipDesc = POINTER(MapiRecipDesc)
class MapiFileDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('flFlags', c_ulong),
('nPosition', c_ulong),
('lpszPathName', c_char_p),
('lpszFileName', c_char_p),
('lpFileType', c_void_p),
]
lpMapiFileDesc = POINTER(MapiFileDesc)
class MapiMessage(Structure):
_fields_ = [('ulReserved', c_ulong),
('lpszSubject', c_char_p),
('lpszNoteText', c_char_p),
('lpszMessageType', c_char_p),
('lpszDateReceived', c_char_p),
('lpszConversationID', c_char_p),
('flFlags', FLAGS),
('lpOriginator', lpMapiRecipDesc), # ignored?
('nRecipCount', c_ulong),
('lpRecips', lpMapiRecipDesc),
('nFileCount', c_ulong),
('lpFiles', lpMapiFileDesc),
]
lpMapiMessage = POINTER(MapiMessage)
MAPI = windll.mapi32
MAPISendMail=MAPI.MAPISendMail
MAPISendMail.restype = c_ulong # Error code
MAPISendMail.argtypes = (LHANDLE, # lhSession
c_ulong, # ulUIParam
lpMapiMessage, # lpMessage
FLAGS, # lpFlags
c_ulong, # ulReserved
)
def SendMail(recipient, subject, body, attach=[]):
"""Post an e-mail message using Simple MAPI
recipient - string: address to send to
subject - string: subject header
body - string: message text
attach - string: files to attach
"""
attach = map( os.path.abspath, attach )
nFileCount = len(attach)
if attach:
MapiFileDesc_A = MapiFileDesc * len(attach)
fda = MapiFileDesc_A()
for fd, fa in zip(fda, attach):
fd.ulReserved = 0
fd.flFlags = 0
fd.nPosition = -1
fd.lpszPathName = fa
fd.lpszFileName = None
fd.lpFileType = None
lpFiles = fda
recip = MapiRecipDesc(0, MAPI_TO, None, recipient, 0, None)
#msg = MapiMessage(0, subject, body, None, None, None, 0,
# cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
# nFileCount, cast(NULL, lpMapiFileDesc))
msg = MapiMessage(0, subject, body, None, None, None, 0,
cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
nFileCount, cast(NULL, lpFiles))
rc = MAPISendMail(0, 0, byref(msg), 0, 0)
if rc != SUCCESS_SUCCESS:
raise WindowsError, "MAPI error %i" % rc

Jul 18 '05 #28

P: n/a
ia*@kirbyfooty.com writes:
Hi Lenard,

As the risk of severely embarassing myself can I ask for your help one
more time.
I have tried changing your script to include attachments, but guess
what, (and this should come as no suprise) I can't do it.
So....
Here is my feeble attempt at changing the script..
Actually the only real problem is with the lpFiles argument
to the MapiMessage constructor call.
---------------------------------------------------------------------------------------- [snip]
def SendMail(recipient, subject, body, attach=[]):
"""Post an e-mail message using Simple MAPI
recipient - string: address to send to
subject - string: subject header
body - string: message text
attach - string: files to attach
"""
attach = map( os.path.abspath, attach )
nFileCount = len(attach)
if attach:
MapiFileDesc_A = MapiFileDesc * len(attach)
fda = MapiFileDesc_A()
for fd, fa in zip(fda, attach):
fd.ulReserved = 0
fd.flFlags = 0
fd.nPosition = -1
fd.lpszPathName = fa
fd.lpszFileName = None
fd.lpFileType = None
lpFiles = fda
Add this else clause to the "if attach:"

else:
# No attachments
lpFiles = cast(NULL, lpMapiFileDesc) # Make NULL


recip = MapiRecipDesc(0, MAPI_TO, None, recipient, 0, None)
#msg = MapiMessage(0, subject, body, None, None, None, 0,
# cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
# nFileCount, cast(NULL, lpMapiFileDesc))
msg = MapiMessage(0, subject, body, None, None, None, 0,
cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
nFileCount, cast(NULL, lpFiles))
Replace "cast(NULL, lpFiles)" with "lpFiles".

rc = MAPISendMail(0, 0, byref(msg), 0, 0)
if rc != SUCCESS_SUCCESS:
raise WindowsError, "MAPI error %i" % rc


And that is it.

The "cast(NULL, lpFiles)" was a way of assigning a null value to
the lpFiles member of the MapiMessage structure. Using None did
not work. But recasting a c_void_p(None) did.

Lenard Lindstrom
<le***@telus.net>
Jul 18 '05 #29

P: n/a
ian
Hello again,
Thanks for the advice!
Unfortunately I still cannot get it to send attachments.
It comes up with the following windows error..
(I have a feeling it has something to do with the file count)
import simplemapi
simplemapi.SendMail("ia*@cgbs.com.au","The Subject","The

body","c:\ian\ian.txt")
nFileCount 14
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "simplemapi.py", line 111, in SendMail
raise WindowsError, "MAPI error %i" % rc
WindowsError: MAPI error 2
This is the updated script..

----------------------------------
import os
from ctypes import *

FLAGS = c_ulong
LHANDLE = c_ulong
LPLHANDLE = POINTER(LHANDLE)
# Return codes
SUCCESS_SUCCESS = 0
# Recipient class
MAPI_ORIG = 0
MAPI_TO = 1
NULL = c_void_p(None)
class MapiRecipDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('ulRecipClass', c_ulong),
('lpszName', c_char_p),
('lpszAddress', c_char_p),
('ulEIDSize', c_ulong),
('lpEntryID', c_void_p),
]
lpMapiRecipDesc = POINTER(MapiRecipDesc)
class MapiFileDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('flFlags', c_ulong),
('nPosition', c_ulong),
('lpszPathName', c_char_p),
('lpszFileName', c_char_p),
('lpFileType', c_void_p),
]
lpMapiFileDesc = POINTER(MapiFileDesc)
class MapiMessage(Structure):
_fields_ = [('ulReserved', c_ulong),
('lpszSubject', c_char_p),
('lpszNoteText', c_char_p),
('lpszMessageType', c_char_p),
('lpszDateReceived', c_char_p),
('lpszConversationID', c_char_p),
('flFlags', FLAGS),
('lpOriginator', lpMapiRecipDesc), # ignored?
('nRecipCount', c_ulong),
('lpRecips', lpMapiRecipDesc),
('nFileCount', c_ulong),
('lpFiles', lpMapiFileDesc),
]
lpMapiMessage = POINTER(MapiMessage)
MAPI = windll.mapi32
MAPISendMail=MAPI.MAPISendMail
MAPISendMail.restype = c_ulong # Error code
MAPISendMail.argtypes = (LHANDLE, # lhSession
c_ulong, # ulUIParam
lpMapiMessage, # lpMessage
FLAGS, # lpFlags
c_ulong, # ulReserved
)
def SendMail(recipient, subject, body, attach=[]):
"""Post an e-mail message using Simple MAPI
recipient - string: address to send to
subject - string: subject header
body - string: message text
attach - string: files to attach
"""
attach = map( os.path.abspath, attach )
nFileCount = len(attach)
if attach:
MapiFileDesc_A = MapiFileDesc * len(attach)
fda = MapiFileDesc_A()
for fd, fa in zip(fda, attach):
fd.ulReserved = 0
fd.flFlags = 0
fd.nPosition = -1
fd.lpszPathName = fa
fd.lpszFileName = None
fd.lpFileType = None
lpFiles = fda
else:
# No attachments
lpFiles = cast(NULL, lpMapiFileDesc) # Make NULL

print "nFileCount ",nFileCount
recip = MapiRecipDesc(0, MAPI_TO, None, recipient, 0, None)
#msg = MapiMessage(0, subject, body, None, None, None, 0,
# cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
# nFileCount, cast(NULL, lpMapiFileDesc))
msg = MapiMessage(0, subject, body, None, None, None, 0,
cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
nFileCount, lpFiles)
rc = MAPISendMail(0, 0, byref(msg), 0, 0)
if rc != SUCCESS_SUCCESS:
raise WindowsError, "MAPI error %i" % rc

--------------------------

Thanks again for your help so far on this. I really appreciate it!
Have a safe and very merry Christmas.

God bless!!

Ian

Jul 18 '05 #30

P: n/a
ia*@kirbyfooty.com writes:
Hello again,
Thanks for the advice!
Unfortunately I still cannot get it to send attachments.
It comes up with the following windows error..
(I have a feeling it has something to do with the file count)
import simplemapi
simplemapi.SendMail("ia*@cgbs.com.au","The Subject","The
body","c:\ian\ian.txt")
nFileCount 14
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "simplemapi.py", line 111, in SendMail
raise WindowsError, "MAPI error %i" % rc
WindowsError: MAPI error 2


Two problems:

1) SendMail is looking for a list of attachment files.
2) SendMail wants the attachments to be in the current
working directory; that is what the:

attach = map( os.path.abspath, attach )

is about, right?

Try this:

import simplemapi
import os
os.chdir("c:\ian")
simplemapi.SendMail("ia*@cgbs.com.au", "The Subject",
"The body", ["ian.txt"])

This is the updated script..

----------------------------------
import os
from ctypes import *

FLAGS = c_ulong
LHANDLE = c_ulong
LPLHANDLE = POINTER(LHANDLE)
# Return codes
SUCCESS_SUCCESS = 0
# Recipient class
MAPI_ORIG = 0
MAPI_TO = 1
NULL = c_void_p(None)
class MapiRecipDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('ulRecipClass', c_ulong),
('lpszName', c_char_p),
('lpszAddress', c_char_p),
('ulEIDSize', c_ulong),
('lpEntryID', c_void_p),
]
lpMapiRecipDesc = POINTER(MapiRecipDesc)
class MapiFileDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('flFlags', c_ulong),
('nPosition', c_ulong),
('lpszPathName', c_char_p),
('lpszFileName', c_char_p),
('lpFileType', c_void_p),
]
lpMapiFileDesc = POINTER(MapiFileDesc)
class MapiMessage(Structure):
_fields_ = [('ulReserved', c_ulong),
('lpszSubject', c_char_p),
('lpszNoteText', c_char_p),
('lpszMessageType', c_char_p),
('lpszDateReceived', c_char_p),
('lpszConversationID', c_char_p),
('flFlags', FLAGS),
('lpOriginator', lpMapiRecipDesc), # ignored?
('nRecipCount', c_ulong),
('lpRecips', lpMapiRecipDesc),
('nFileCount', c_ulong),
('lpFiles', lpMapiFileDesc),
]
lpMapiMessage = POINTER(MapiMessage)
MAPI = windll.mapi32
MAPISendMail=MAPI.MAPISendMail
MAPISendMail.restype = c_ulong # Error code
MAPISendMail.argtypes = (LHANDLE, # lhSession
c_ulong, # ulUIParam
lpMapiMessage, # lpMessage
FLAGS, # lpFlags
c_ulong, # ulReserved
)
def SendMail(recipient, subject, body, attach=[]):
"""Post an e-mail message using Simple MAPI
recipient - string: address to send to
subject - string: subject header
body - string: message text
attach - string: files to attach
"""
attach = map( os.path.abspath, attach )
nFileCount = len(attach)
if attach:
MapiFileDesc_A = MapiFileDesc * len(attach)
fda = MapiFileDesc_A()
for fd, fa in zip(fda, attach):
fd.ulReserved = 0
fd.flFlags = 0
fd.nPosition = -1
fd.lpszPathName = fa
fd.lpszFileName = None
fd.lpFileType = None
lpFiles = fda
else:
# No attachments
lpFiles = cast(NULL, lpMapiFileDesc) # Make NULL

print "nFileCount ",nFileCount
recip = MapiRecipDesc(0, MAPI_TO, None, recipient, 0, None)
#msg = MapiMessage(0, subject, body, None, None, None, 0,
# cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
# nFileCount, cast(NULL, lpMapiFileDesc))
msg = MapiMessage(0, subject, body, None, None, None, 0,
cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
nFileCount, lpFiles)
rc = MAPISendMail(0, 0, byref(msg), 0, 0)
if rc != SUCCESS_SUCCESS:
raise WindowsError, "MAPI error %i" % rc

--------------------------

Thanks again for your help so far on this. I really appreciate it!
Have a safe and very merry Christmas.

And the same to you.

Lenard Lindstrom
<le***@telus.net>
Jul 18 '05 #31

P: n/a
ian
Hi Lenard,
You just beat me to it.
Suprise, suprise, I discovered the answer myself this time.

I have modified the script to allow the attachment(s) to still be
passed as a string.
Some error checking is also done to verify the attachment file exists.

I have also modified it so it can be used for multiple email addresses.

Here is the updated working script ...
---------------------------------------------------------

import os
from ctypes import *

FLAGS = c_ulong
LHANDLE = c_ulong
LPLHANDLE = POINTER(LHANDLE)
# Return codes
SUCCESS_SUCCESS = 0
# Recipient class
MAPI_ORIG = 0
MAPI_TO = 1
NULL = c_void_p(None)
class MapiRecipDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('ulRecipClass', c_ulong),
('lpszName', c_char_p),
('lpszAddress', c_char_p),
('ulEIDSize', c_ulong),
('lpEntryID', c_void_p),
]
lpMapiRecipDesc = POINTER(MapiRecipDesc)
class MapiFileDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('flFlags', c_ulong),
('nPosition', c_ulong),
('lpszPathName', c_char_p),
('lpszFileName', c_char_p),
('lpFileType', c_void_p),
]
lpMapiFileDesc = POINTER(MapiFileDesc)
class MapiMessage(Structure):
_fields_ = [('ulReserved', c_ulong),
('lpszSubject', c_char_p),
('lpszNoteText', c_char_p),
('lpszMessageType', c_char_p),
('lpszDateReceived', c_char_p),
('lpszConversationID', c_char_p),
('flFlags', FLAGS),
('lpOriginator', lpMapiRecipDesc), # ignored?
('nRecipCount', c_ulong),
('lpRecips', lpMapiRecipDesc),
('nFileCount', c_ulong),
('lpFiles', lpMapiFileDesc),
]
lpMapiMessage = POINTER(MapiMessage)
MAPI = windll.mapi32
MAPISendMail=MAPI.MAPISendMail
MAPISendMail.restype = c_ulong # Error code
MAPISendMail.argtypes = (LHANDLE, # lhSession
c_ulong, # ulUIParam
lpMapiMessage, # lpMessage
FLAGS, # lpFlags
c_ulong, # ulReserved
)
def SendMail(recipient, subject, body, attachfiles):
"""Post an e-mail message using Simple MAPI
recipient - string: address to send to (multiple address sperated
with a semicolin)
subject - string: subject header
body - string: message text
attach - string: files to attach (multiple attachments sperated
with a semicolin)

Example usage
import simplemapi

simplemapi.SendMail("to********@server.com;to***** ***@server.com","My
Subject","My message body","c:\attachment1.txt;c:\attchment2")
"""

# get list of file attachments
attach = []
AttachWork = attachfiles.split(';')

#verify the attachment file exists
for file in AttachWork:
if os.path.exists(file):
attach.append(file)
attach = map( os.path.abspath, attach )
nFileCount = len(attach)

if attach:
MapiFileDesc_A = MapiFileDesc * len(attach)
fda = MapiFileDesc_A()
for fd, fa in zip(fda, attach):
fd.ulReserved = 0
fd.flFlags = 0
fd.nPosition = -1
fd.lpszPathName = fa
fd.lpszFileName = None
fd.lpFileType = None
lpFiles = fda
else:
# No attachments
lpFiles = cast(NULL, lpMapiFileDesc) # Make NULL

# Get the number of recipients
RecipWork = recipient.split(';')
RecipCnt = len(RecipWork)

# Formulate the recipients
MapiRecipDesc_A = MapiRecipDesc * len(RecipWork)
rda = MapiRecipDesc_A()
for rd, ra in zip(rda, RecipWork):
rd.ulReserved = 0
rd.ulRecipClass = MAPI_TO
rd.lpszName = None
rd.lpszAddress = ra
rd.ulEIDSize = 0
rd.lpEntryID = None
recip = rda

# send the message
msg = MapiMessage(0, subject, body, None, None, None, 0,
cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
nFileCount, lpFiles)
rc = MAPISendMail(0, 0, byref(msg), 0, 0)
if rc != SUCCESS_SUCCESS:
raise WindowsError, "MAPI error %i" % rc
-----------------------------------

Jul 18 '05 #32

P: n/a
ian
I wish I new why google doesn't show nicely aligned python code when
you paste the script.
Anyways, in case this helps someone else you can download the script
from
http://www.kirbyfooty.com/simplemapi.py

Ian

Jul 18 '05 #33

P: n/a
ia*@kirbyfooty.com writes:
Hi Lenard,
You just beat me to it.
Suprise, suprise, I discovered the answer myself this time.

I have modified the script to allow the attachment(s) to still be
passed as a string.
Some error checking is also done to verify the attachment file exists.

I have also modified it so it can be used for multiple email addresses.

Here is the updated working script ...
---------------------------------------------------------

import os
from ctypes import *

FLAGS = c_ulong
LHANDLE = c_ulong
LPLHANDLE = POINTER(LHANDLE)
# Return codes
SUCCESS_SUCCESS = 0
# Recipient class
MAPI_ORIG = 0
MAPI_TO = 1
NULL = c_void_p(None)
class MapiRecipDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('ulRecipClass', c_ulong),
('lpszName', c_char_p),
('lpszAddress', c_char_p),
('ulEIDSize', c_ulong),
('lpEntryID', c_void_p),
]
lpMapiRecipDesc = POINTER(MapiRecipDesc)
class MapiFileDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('flFlags', c_ulong),
('nPosition', c_ulong),
('lpszPathName', c_char_p),
('lpszFileName', c_char_p),
('lpFileType', c_void_p),
]
lpMapiFileDesc = POINTER(MapiFileDesc)
class MapiMessage(Structure):
_fields_ = [('ulReserved', c_ulong),
('lpszSubject', c_char_p),
('lpszNoteText', c_char_p),
('lpszMessageType', c_char_p),
('lpszDateReceived', c_char_p),
('lpszConversationID', c_char_p),
('flFlags', FLAGS),
('lpOriginator', lpMapiRecipDesc), # ignored?
('nRecipCount', c_ulong),
('lpRecips', lpMapiRecipDesc),
('nFileCount', c_ulong),
('lpFiles', lpMapiFileDesc),
]
lpMapiMessage = POINTER(MapiMessage)
MAPI = windll.mapi32
MAPISendMail=MAPI.MAPISendMail
MAPISendMail.restype = c_ulong # Error code
MAPISendMail.argtypes = (LHANDLE, # lhSession
c_ulong, # ulUIParam
lpMapiMessage, # lpMessage
FLAGS, # lpFlags
c_ulong, # ulReserved
)
def SendMail(recipient, subject, body, attachfiles):
"""Post an e-mail message using Simple MAPI
recipient - string: address to send to (multiple address sperated
with a semicolin)
subject - string: subject header
body - string: message text
attach - string: files to attach (multiple attachments sperated
with a semicolin)

Example usage
import simplemapi

simplemapi.SendMail("to********@server.com;to***** ***@server.com","My
Subject","My message body","c:\attachment1.txt;c:\attchment2")
"""

# get list of file attachments
attach = []
AttachWork = attachfiles.split(';')

#verify the attachment file exists
for file in AttachWork:
if os.path.exists(file):
attach.append(file)
attach = map( os.path.abspath, attach )
nFileCount = len(attach)

if attach:
MapiFileDesc_A = MapiFileDesc * len(attach)
fda = MapiFileDesc_A()
for fd, fa in zip(fda, attach):
fd.ulReserved = 0
fd.flFlags = 0
fd.nPosition = -1
fd.lpszPathName = fa
fd.lpszFileName = None
fd.lpFileType = None
lpFiles = fda
else:
# No attachments
lpFiles = cast(NULL, lpMapiFileDesc) # Make NULL

# Get the number of recipients
RecipWork = recipient.split(';')
RecipCnt = len(RecipWork)

# Formulate the recipients
MapiRecipDesc_A = MapiRecipDesc * len(RecipWork)
rda = MapiRecipDesc_A()
for rd, ra in zip(rda, RecipWork):
rd.ulReserved = 0
rd.ulRecipClass = MAPI_TO
rd.lpszName = None
rd.lpszAddress = ra
rd.ulEIDSize = 0
rd.lpEntryID = None
recip = rda

# send the message
msg = MapiMessage(0, subject, body, None, None, None, 0,
cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
nFileCount, lpFiles)
rc = MAPISendMail(0, 0, byref(msg), 0, 0)
if rc != SUCCESS_SUCCESS:
raise WindowsError, "MAPI error %i" % rc
-----------------------------------


Looks good.

Lenard Lindstrom
Jul 18 '05 #34

P: n/a
Lenard Lindstrom wrote:
ia*@kirbyfooty.com writes:

Hi Lenard,
You just beat me to it.
Suprise, suprise, I discovered the answer myself this time.

I have modified the script to allow the attachment(s) to still be
passed as a string.
Some error checking is also done to verify the attachment file exists.

I have also modified it so it can be used for multiple email addresses.

Here is the updated working script ...
---------------------------------------------------------

import os
from ctypes import *

FLAGS = c_ulong
LHANDLE = c_ulong
LPLHANDLE = POINTER(LHANDLE)
# Return codes
SUCCESS_SUCCESS = 0
# Recipient class
MAPI_ORIG = 0
MAPI_TO = 1
NULL = c_void_p(None)
class MapiRecipDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('ulRecipClass', c_ulong),
('lpszName', c_char_p),
('lpszAddress', c_char_p),
('ulEIDSize', c_ulong),
('lpEntryID', c_void_p),
]
lpMapiRecipDesc = POINTER(MapiRecipDesc)
class MapiFileDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('flFlags', c_ulong),
('nPosition', c_ulong),
('lpszPathName', c_char_p),
('lpszFileName', c_char_p),
('lpFileType', c_void_p),
]
lpMapiFileDesc = POINTER(MapiFileDesc)
class MapiMessage(Structure):
_fields_ = [('ulReserved', c_ulong),
('lpszSubject', c_char_p),
('lpszNoteText', c_char_p),
('lpszMessageType', c_char_p),
('lpszDateReceived', c_char_p),
('lpszConversationID', c_char_p),
('flFlags', FLAGS),
('lpOriginator', lpMapiRecipDesc), # ignored?
('nRecipCount', c_ulong),
('lpRecips', lpMapiRecipDesc),
('nFileCount', c_ulong),
('lpFiles', lpMapiFileDesc),
]
lpMapiMessage = POINTER(MapiMessage)
MAPI = windll.mapi32
MAPISendMail=MAPI.MAPISendMail
MAPISendMail.restype = c_ulong # Error code
MAPISendMail.argtypes = (LHANDLE, # lhSession
c_ulong, # ulUIParam
lpMapiMessage, # lpMessage
FLAGS, # lpFlags
c_ulong, # ulReserved
)
def SendMail(recipient, subject, body, attachfiles):
"""Post an e-mail message using Simple MAPI
recipient - string: address to send to (multiple address sperated
with a semicolin)
subject - string: subject header
body - string: message text
attach - string: files to attach (multiple attachments sperated
with a semicolin)

Example usage
import simplemapi

simplemapi.SendMail("to********@server.com;to*** *****@server.com","My
Subject","My message body","c:\attachment1.txt;c:\attchment2")
"""

# get list of file attachments
attach = []
AttachWork = attachfiles.split(';')

#verify the attachment file exists
for file in AttachWork:
if os.path.exists(file):
attach.append(file)
attach = map( os.path.abspath, attach )
nFileCount = len(attach)

if attach:
MapiFileDesc_A = MapiFileDesc * len(attach)
fda = MapiFileDesc_A()
for fd, fa in zip(fda, attach):
fd.ulReserved = 0
fd.flFlags = 0
fd.nPosition = -1
fd.lpszPathName = fa
fd.lpszFileName = None
fd.lpFileType = None
lpFiles = fda
else:
# No attachments
lpFiles = cast(NULL, lpMapiFileDesc) # Make NULL

# Get the number of recipients
RecipWork = recipient.split(';')
RecipCnt = len(RecipWork)

# Formulate the recipients
MapiRecipDesc_A = MapiRecipDesc * len(RecipWork)
rda = MapiRecipDesc_A()
for rd, ra in zip(rda, RecipWork):
rd.ulReserved = 0
rd.ulRecipClass = MAPI_TO
rd.lpszName = None
rd.lpszAddress = ra
rd.ulEIDSize = 0
rd.lpEntryID = None
recip = rda

# send the message
msg = MapiMessage(0, subject, body, None, None, None, 0,
cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
nFileCount, lpFiles)
rc = MAPISendMail(0, 0, byref(msg), 0, 0)
if rc != SUCCESS_SUCCESS:
raise WindowsError, "MAPI error %i" % rc
-----------------------------------

Looks good.

Lenard Lindstrom


Nice quoting

--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
Jul 18 '05 #35

P: n/a
Max M wrote:
Lenard Lindstrom wrote:
ia*@kirbyfooty.com writes:
[sixty or more lines, mostly code ...]

Looks good.

Lenard Lindstrom

Nice quoting

So what is this, some kind of competition? If you really though Lenard's
quoting was a sin (since I took your remarks to be sardonic), how much
more so was your gratuitous repetition thereof?

Far more pleasant to either a) ignore a gaff by a possibly
less-experienced usenet correspondent than yourself, or b) point out the
error without repeating it, as I hope I have done here.

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #36

P: n/a
ian
Hey guys, I'm just thankful the answer has been found and hope this
helps someone else. To everyone (especially Lenard) that responded to
my request for help, thank you!!
Merry Christmas everyone!!!
God bless
Ian

Jul 18 '05 #37

P: n/a
Steve Holden wrote:
Max M wrote:
Lenard Lindstrom wrote:
So what is this, some kind of competition? If you really though Lenard's
quoting was a sin (since I took your remarks to be sardonic), how much
more so was your gratuitous repetition thereof?
I thought that showing by example might have a better effect than just
grumping.

Far more pleasant to either a) ignore a gaff by a possibly
less-experienced usenet correspondent than yourself, or b) point out the
error without repeating it, as I hope I have done here.


You are right.
--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
Jul 18 '05 #38

P: n/a
ia*@kirbyfooty.com wrote:
Hey guys, I'm just thankful the answer has been found and hope this
helps someone else. To everyone (especially Lenard) that responded to
my request for help, thank you!!
Merry Christmas everyone!!!
God bless
Ian

Thanks Ian, Why not post this to the python-win32 mailing list as well,
then maybe your changes can be incorporated into pywin32?

Happy christmas
David
Jul 18 '05 #39

P: n/a
ian
Hi David,
I'd be happy to post it to python-win32 but don't know how.
Ian

Jul 18 '05 #40

P: n/a
ia*@kirbyfooty.com wrote:
Hi David,
I'd be happy to post it to python-win32 but don't know how.
Ian

Send mail to py**********@python.org. If you want to see it arrive you
might join the list beforehand - go to www.python.org and follow the
"Mailing Lists" link to find out how to subscribe.

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #41

This discussion thread is closed

Replies have been disabled for this discussion.