Hi Tim, I was able to test that clearing the read flag and setting delete after submit didn't result in the email ending up in sent items. When delete after submit is set it does however at least get removed from the outbox.
I should probably mention I'm running this against outlook 2003 on windows xp (as high as we've upgraded here at my job...) I even tried to explicitly call moveMessages on the outbox folder and move it to sent items folder 'manually' so to speak - no errors from this, but no joy either. I've included my code below for anyone who can see issues with it or has suggestions. I don't suppose anyone has an outlook 2003 setup they could try to send an email via and see if it ends up in sent?? """module to send mail with Extended MAPI using the pywin32 mapi wrappers...""" # this was based on Jason Hattingh's C++ code at http://www.codeproject.com/internet/mapadmin.asp # written by David Fraser <davidf at sjsoft.com> and Stephen Emslie <stephene at sjsoft.com> # you can test this by changing the variables at the bottom and running from the command line from win32com.mapi import mapi from win32com.mapi import mapitags def SendEMAPIMail(Subject="", Message="", SendTo=None, SendCC=None, SendBCC=None, MAPIProfile=None): """Sends an email to the recipient using the extended MAPI interface Subject and Message are strings Send{To,CC,BCC} are comma-separated address lists MAPIProfile is the name of the MAPI profile""" # initialize and log on mapi.MAPIInitialize(None) session = mapi.MAPILogonEx(0, None, None, mapi.MAPI_EXTENDED | mapi.MAPI_USE_DEFAULT) messagestorestable = session.GetMsgStoresTable(0) messagestorestable.SetColumns((mapitags.PR_ENTRYID, mapitags.PR_DISPLAY_NAME_A, mapitags.PR_DEFAULT_STORE),0) foundDefStore = False while (True): foundDefStore = False rows = messagestorestable.QueryRows(1, 0) if len(rows) != 1: break row = rows[0] for x in range(len(row)): propertyid, propertyvalue = row[x] if (propertyid == mapitags.PR_DEFAULT_STORE and propertyvalue == True): foundDefStore = True break if (foundDefStore): break # unpack the row and open the message store (eid_tag, eid), (name_tag, name), (def_store_tag, def_store) = row msgstore = session.OpenMsgStore(0,eid,None,mapi.MDB_NO_DIALOG | mapi.MAPI_BEST_ACCESS) # get the outbox hr, props = msgstore.GetProps((mapitags.PR_IPM_OUTBOX_ENTRYID), 0) (tag, eid) = props[0] outboxfolder = msgstore.OpenEntry(eid,None,mapi.MAPI_BEST_ACCESS) #get the 'sent items' folder - by default. we will have to get the user's #desired folder as well, if they've changed it... hr, props = msgstore.GetProps((mapitags.PR_IPM_SENTMAIL_ENTRYID), 0) (tag, eid) = props[0] destFolder = msgstore.OpenEntry(eid, None, mapi.MAPI_BEST_ACCESS) # create the message and the addrlist message = outboxfolder.CreateMessage(None,0) # note: you can use the resolveaddress functions for this. but you may get headaches pal = [] def makeentry(recipient, recipienttype): return ((mapitags.PR_RECIPIENT_TYPE, recipienttype), (mapitags.PR_SEND_RICH_INFO, False), (mapitags.PR_DISPLAY_TYPE, 0), (mapitags.PR_OBJECT_TYPE, 6), (mapitags.PR_EMAIL_ADDRESS_A, recipient), (mapitags.PR_ADDRTYPE_A, 'SMTP'), (mapitags.PR_DISPLAY_NAME_A, recipient)) if SendTo: pal.extend([makeentry(recipient, mapi.MAPI_TO) for recipient in SendTo.split(",")]) if SendCC: pal.extend([makeentry(recipient, mapi.MAPI_CC) for recipient in SendCC.split(",")]) if SendBCC: pal.extend([makeentry(recipient, mapi.MAPI_BCC) for recipient in SendBCC.split(",")]) # add the resolved recipients to the message message.ModifyRecipients(mapi.MODRECIP_ADD,pal) message.SetProps([(mapitags.PR_BODY_HTML_A,Message), (mapitags.PR_SUBJECT_A,Subject), (mapitags.PR_DELETE_AFTER_SUBMIT, 1)]) # save changes and submit outboxfolder.SaveChanges(0) message.SubmitMessage(0) message.SetReadFlag(0) #get the message id so i can move it... hr, props = message.GetProps((mapitags.PR_ENTRYID),0) (msg_eid_tag, msg_eid) = props[0] #1 is MESSAGE_MOVE according to msdn docs but i don't feel like figuring out if it has a symbolic constant or not... outboxfolder.CopyMessages([msg_eid], None, destFolder, 0, None, 1) ________________________________ From: Tim Roberts [mailto:t...@probo.com] Sent: Wednesday, June 05, 2013 10:35 AM To: Aubin LaBrosse; Python-Win32 List Subject: Re: [python-win32] PySBinaryArray?? Aubin LaBrosse wrote: Mail server is exchange Last calls I made are: outboxfolder.SaveChanges(0) message.SubmitMessage(0) outlook is 100% online, yes for whatever reason when I send programmatically in this way I never see it move to sent items - it just hangs out in the outbox. So I just assumed I had to move it myself. No, that's not the right answer. You don't really want the message in "Sent Items". What you want is for Outlook to move it to "Sent Items" because it got sent. Did you say you had tried doing this before SaveChanges: message.SetReadFlag(CLEAR_READ_FLAG) message.SetProps([(mapitags.PR_DELETE_AFTER_SUBMIT,1)]) -- Tim Roberts, t...@probo.com<mailto:t...@probo.com> Providenza & Boekelheide, Inc.
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32