Error with Simplemapi.py

M

Mick Duprez

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
fromhttp://www.kirbyfooty.com/simplemapi.py

Ian

First of all, thanks to all involved, this looks like what I need
without re-inventing the wheel.
Sorry to Ian if he just recieved 2 emails, my bad, I need to learn how
to use this board better!

I have a small problem. I get an error I don't know how to resolve,
any help would be much appreciated.
I'm using Python25 on winXP pro and the script from the link above.
Here's the error -

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
mailtest.SendMail('(e-mail address removed)','test','test string','c:
\dbs.txt')
File "C:\Python25\mailtest.py", line 135, in SendMail
cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
File "C:\Python25\lib\ctypes\__init__.py", line 478, in cast
return _cast(obj, obj, typ)

I have had a brief look at the C api for these structs and functions
but I can't resolve it, it is probably something simple.
The piece of code I don't understand though is this -

MapiRecipDesc_A = MapiRecipDesc * len(RecipWork) #size of struct??
rda = MapiRecipDesc_A() # isn't it MapiRecipDesc as declared??

There's some new stuff going on here I don't understand.

thanks for your help,
Mick.
 
G

Gabriel Genellina

I have a small problem. I get an error I don't know how to resolve,
any help would be much appreciated.
I'm using Python25 on winXP pro and the script from the link above.
Here's the error -

That should be 'c:\\dbs.txt' or r'c:\dbs.txt'
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
mailtest.SendMail('(e-mail address removed)','test','test string','c:
\dbs.txt')
File "C:\Python25\mailtest.py", line 135, in SendMail
cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
File "C:\Python25\lib\ctypes\__init__.py", line 478, in cast
return _cast(obj, obj, typ)

I'm unsure what those cast(NULL, ...) are supposed to do, but they look
all wrong. NULL, as defined on that script, is *not* a C NULL pointer (use
None for that).
(In fact the whole script doesn't look well at all - do you *have* to use
MAPI? can't use SMTP instead? Even if you must use MAPI, try the pywin32
package from Mark Hammond, it has MAPI support and a demo script for
sending mail)
I have had a brief look at the C api for these structs and functions
but I can't resolve it, it is probably something simple.
The piece of code I don't understand though is this -

MapiRecipDesc_A = MapiRecipDesc * len(RecipWork) #size of struct??

This declares a new type, an array of len(RecipWork) items, each of type
MapiRecipDesc
rda = MapiRecipDesc_A() # isn't it MapiRecipDesc as declared??

This creates an instance of the above array.
 
M

Mick Duprez

That should be 'c:\\dbs.txt' or r'c:\dbs.txt'


I'm unsure what those cast(NULL, ...) are supposed to do, but they look
all wrong. NULL, as defined on that script, is *not* a C NULL pointer (use
None for that).
(In fact the whole script doesn't look well at all - do you *have* to use
MAPI? can't use SMTP instead? Even if you must use MAPI, try the pywin32
package from Mark Hammond, it has MAPI support and a demo script for
sending mail)



This declares a new type, an array of len(RecipWork) items, each of type
MapiRecipDesc


This creates an instance of the above array.

Thank you very much Gabriel, changing the NULL to None did the trick
(it also helps if I reload the changed module after editing!:( ). Yes
that is an old script and I will look into your suggestions. Basically
I'd just like to use the default mail client (windows or Unix/Linux)
to send simple mail with attachments, this way I can log the
attachments I send to a db for example for document transmittal/
register reports etc.
Thanks also for the code explanations,
Cheers,
Mick.
 
G

Gabriel Genellina

Thank you very much Gabriel, changing the NULL to None did the trick
(it also helps if I reload the changed module after editing!:( ).

Glad to see it worked.
Yes
that is an old script and I will look into your suggestions. Basically
I'd just like to use the default mail client (windows or Unix/Linux)
to send simple mail with attachments, this way I can log the
attachments I send to a db for example for document transmittal/
register reports etc.

Hmmm... altough you may find some MAPI implementation for Linux, it's very
uncommon; consider using sendmail instead, or ask for an outbound SMTP
server and use the smtplib module.
 
M

Mick Duprez

Glad to see it worked.


Hmmm... altough you may find some MAPI implementation for Linux, it's very
uncommon; consider using sendmail instead, or ask for an outbound SMTP
server and use the smtplib module.

Will do, thanks for your time,
Mick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,802
Messages
2,569,661
Members
45,431
Latest member
AidaVardon

Latest Threads

Top