Jump to content

Send attchement as PDF in an Email


Recommended Posts



I found the really cool lisp routine to send an AutoCAD drawing as an attachment in an Email and was wondering if it could be modified to send a PDF instead.


(defun c:eMail (/ _catch file outlook email)
 ;; Using Outlook, eMail selected object(s) in a temporary DWG file
 ;; Many thanks to Ron Perez (ronjonp) for the Outlook example ([url]http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794[/url])
 ;; Alan J. Thompson, 03.28.11
 (defun _catch (f a) (not (vl-catch-all-error-p (vl-catch-all-apply f a))))
     (or (ssget "_I") (prompt "\nSelect object(s) to eMail: ") (ssget))
     (setq file (vl-filename-mktemp "" nil ".dwg"))
     (_catch 'vla-WBlock
             (list (cond (*AcadDoc*)
                         ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
                   (vla-get-activeselectionset *AcadDoc*)
     (setq outlook (vlax-get-or-create-object "Outlook.Application"))
     (setq email (vlax-invoke-method outlook 'CreateItem 0))
     (_catch 'vlax-put (list email 'Subject (strcat "Emailing: " (vl-filename-base file) ".dwg")))
     (_catch 'vlax-invoke (list (vlax-get email 'Attachments) 'Add file))
    (progn (princ "\nOutlook active...")
           (vlax-invoke email 'Display :vlax-true)
           (vl-file-delete file)
 (foreach x (list email outlook) (and x (vlax-release-object x)))


Thanks Brian

Link to comment
Share on other sites

Use ronjonp's subfunction from the provided link:

;; Usage:
; (rjp-OutlookMessage
;  "johndoe@nowhere.com;johndoewife@nowhere.com"                         ;; email address (multiple separated by semicolon)
;  "Test Email"                                                          ;; Subject
;  '("C:\\test\\file1.txt" "C:\\test\\file2.txt" "C:\\test\\file3.txt")  ;; Attachments as a list of strings
;  "Nothing to read here :)"                                             ;; Text in body of email
;  nil                                                                   ;; nil will open email to edit...T will send email in the background
; )
(defun rjp-OutlookMessage (To Subject AttachmentList Body Send / objMail objOL)
   (setq objOL (vlax-get-or-create-object "Outlook.Application")) 
   (setq objMail (vlax-invoke-method objOL 'CreateItem 0)) 
     (vlax-put objMail 'To To)
     (vlax-put objMail 'Subject Subject)
     (vlax-put objMail 'Body Body)
     (foreach file AttachmentList (vl-catch-all-apply 'vlax-invoke (list (vlax-get objMail 'Attachments) 'Add file)) )
     (if send (vlax-invoke objMail 'Send) (vlax-invoke objMail 'Display :vlax-true) )
     (vlax-release-object objOL)
     (vlax-release-object objMail)
   ); progn
 ); and
); defun rjp-OutlookMessage


I just modified the formatting per my own taste.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...