Author Topic: Outlook Application  (Read 1661 times)

0 Members and 1 Guest are viewing this topic.

ChrisCarlson

  • Guest
Outlook Application
« on: June 28, 2018, 01:04:57 PM »
Is there a way to combine these? The intent is to try and incorporate the default signature within Outlook. Invoking the display removes the focus from AutoCAD and sets a lock on the AutoCAD UI. Closing the email draft releases AutoCAD to process the second line. If `Body is modified prior to invoking the display, the signature is not included.

Code - Auto/Visual Lisp: [Select]
  1. (vlax-invoke objMail 'Display :vlax-true)
  2. (vlax-put objMail 'Body Body)


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Outlook Application
« Reply #1 on: June 28, 2018, 01:07:49 PM »
What does (vlax-get objMail 'Body) return prior to (vlax-invoke objMail 'Display :vlax-true)?

Perhaps try this?
Code - Auto/Visual Lisp: [Select]
  1. (vlax-put objMail 'Body (strcat Body (vlax-get objMail 'Body)))
  2. (vlax-invoke objMail 'Display :vlax-true)

ChrisCarlson

  • Guest
Re: Outlook Application
« Reply #2 on: June 28, 2018, 02:34:58 PM »
Before being set, `Body is blank. The outlook API appears to have a flag? which removes the default body.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Outlook Application
« Reply #3 on: June 28, 2018, 02:53:40 PM »
Use my example, but try changing all instances of 'body to 'htmlbody:

Code: [Select]
(vlax-put objMail 'htmlbody (strcat Body (vlax-get objMail 'htmlbody)))
(vlax-invoke objMail 'Display :vlax-true)

ChrisCarlson

  • Guest
Re: Outlook Application
« Reply #4 on: June 28, 2018, 03:28:41 PM »
No go but I got it with your help, thanks!  We need to call 'GetInspector prior to setting 'htmlbody with your text.

Code - Auto/Visual Lisp: [Select]
  1. (vlax-get objMail 'GetInspector)

ChrisCarlson

  • Guest
Re: Outlook Application
« Reply #5 on: June 29, 2018, 08:03:55 AM »
Here is RJP's modified code to accept HTML body and include the default signature.

Code - Auto/Visual Lisp: [Select]
  1.        
  2. ;;http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794
  3. ;;Usage:
  4. ; (rjp-OutlookMessage
  5. ;  "johndoe@nowhere.com;johndoewife@nowhere.com"                         ;; email address (multiple separated by semicolon)
  6. ;  "Test Email"                                                          ;; Subject
  7. ;  '("C:\\test\\file1.txt" "C:\\test\\file2.txt" "C:\\test\\file3.txt")  ;; Attachments as a list of strings
  8. ;  "Nothing to read here :)"                                             ;; HTML code for body of email, standard lisp control characters WILL NOT WORK.
  9. ;  nil;; nil will open email to edit...T will send email in the background
  10. ; )
  11. (defun rjp-OutlookMessage (To CC Subject AttachmentList Body Send / objMail objOL)
  12.   (and
  13.         (setq objOL (vlax-get-or-create-object "Outlook.Application"))
  14.         (setq objMail (vlax-invoke-method objOL 'CreateItem 0))
  15.         (progn
  16.           (vlax-get objMail 'GetInspector)
  17.           (vlax-put objMail 'To To)
  18.           (vlax-put objMail 'Cc CC)
  19.           (vlax-put objMail 'Subject Subject)
  20.           (vlax-put objMail 'htmlbody (strcat Body (vlax-get objMail 'htmlbody)))
  21.           (foreach file AttachmentList (vl-catch-all-apply 'vlax-invoke (list (vlax-get objMail 'Attachments) 'Add file)) )
  22.           (if send (vlax-invoke objMail 'Send) (vlax-invoke objMail 'Display :vlax-true) )
  23.           (vlax-release-object objOL)
  24.           (vlax-release-object objMail)
  25.         ); progn
  26.  ); and
  27. ); defun rjp-OutlookMessage

Example call

Code - Auto/Visual Lisp: [Select]
  1. (rjp-OutlookMessage
  2.         "receiver@mail.com"
  3.         "cc@mail.com"
  4.         "Subject Line"
  5.         '("C:\\test\\file1.txt" "C:\\test\\file2.txt" "C:\\test\\file3.txt")
  6.         "<p><font size=\"3\">This is the email body<br \><br \>Must use HTML formatting</font></p>"
  7.         nil
  8. )
« Last Edit: June 29, 2018, 08:08:14 AM by Master_Shake »