I have a need to use MAPI (yes, I know Ted et al: MAPI bad, SMTP good...but this customer wants to see a system generated email in Outlook, review it including file attachment, and then press Send manually).  I thought I was going to have to use the Redemption tool to get around the security issues with Outlook but I'm stunned that this simple code worked on my laptop which has Outlook 2016 on it:

LOCAL oOutlook as Outlook.Application, oNamespace as Outlook.NameSpace, oMailItem as Outlook.MailItem
oOutlook = CREATEOBJECT("Outlook.Application")
#DEFINE olFolderDisplayNormal 0
#DEFINE olMailItem 0
oNameSpace = oOutlook.GetNameSpace("MAPI")
oExplorer = oOutlook.Explorers.Add(oNameSpace.Folders[1],olFolderDisplayNormal)
oMailItem = oOutlook.CreateItem(olMailItem)
WITH oMailItem
    .Subject = 'Testing email send'
    .Body = "Thank you for your participation in the test at " + TTOC(DATETIME())
    .Recipients.Add("[email protected]")
    .Attachments.Add("C:\crap\MyFile.pdf")
    .Save()
    *.Send() && commented out for now as I don't want to auto-send...user wants to review and manually Send
ENDWITH

oExplorer.Activate()


This is basically using the code from the Microsoft Office Automation with Visual FoxPro book from HWP.  (Thanks for the cue, Ted!).  Now the comment and question:

1. I'm amazed that Outlook 2016 let me do this without any
   warning/blocking.  I was thinking I'd have to use the Outlook
   Redemption add-in tool (http://www.dimastr.com/redemption/)
2. The sample code above saves it to the Drafts folder but when I open
   OL via the last line (oExplorer.Activate()), I was hoping to have
   the email front and center so the user could just press the Send
   button after reviewing it manually on screen.  Any ideas how to
   achieve that?

tia,
--Mike




---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


--- StripMime Report -- processed MIME parts ---
multipart/alternative
 text/plain (text body -- kept)
 text/html
---

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: 
https://leafe.com/archives/byMID/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to