Aller au contenu

Messages recommandés

Posté(e)

Bonjour,

 

j'ai trouvé ce lisp sur le forum Autodesk :

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/courriel-with-attachment-using-lisp/td-p/3206476

 

Par défaut l'courriel se fait en texte HTML, est-il possible de forcer le texte "body" du mail en BRUT et pas en HTML ?

Cela vien certainement des paramètres outlook, mais je veux que le texte soit uniquement texte brut.

 

(defun C:CreateMail (/ )

 (setq fname (getvar "dwgname")) ;gets dwg filename and sets as variable
   ; Who's going to get the mail
 (setq recipients_list (list someone@somewhere.com.au))
    ; What is the subject
 (setq subject (strcat "Copy of drawing - " fname))
    ; What is the body
 (setq body (strcat "Hi, Please find the above file attached as requested."))
    ; What are the attachments
 (setq attachments_list (list "C:\\AAA\\test-GT-copy.dwg"));;i have also tried using a variable to specify the filename and path.
 ;(create-courriel recipients_list subject body attachments_list 1)
    ; Do send this mail immediately
 (create-courriel recipients_list subject body attachments_list 0) ; Do not yet send this mail
 (princ)
)

(defun create-courriel (recipients_list   subject
      body        attachments_list
      email_send        /
      acadapp        acaddoc
      outlookapp        mail_object
      recipients_collection
      attachments_collection
      temp        ret
      item        cadz3d_function
     )
 ;; Load the extended AutoLISP functions and ActiveX support
 (vl-load-com)
 ;; Get the application and current document objects
 (setq acadapp (vlax-get-acad-object)
acaddoc (vlax-get-property acadapp 'activedocument)
 )
 ;; Get the existing outlook application object
 (if (or (= (setq outlookapp
     (vl-catch-all-apply
       'vlax-get-object
       (list "Outlook.Application")
     )
     )
     nil
  )
  (/= (type outlookapp) 'vla-object)
     )
   (progn (alert (strcat
     "Microsoft Outlook must already be running\n"
     "to create and send the courriel.\n"
     "Please start Microsoft Outlook and then close\n"
     "this dialog box to create the courriel.")
   )
   (setq outlookapp
   (vl-catch-all-apply
     'vlax-get-object
     (list "Outlook.Application")
   )
   )
   )
 )
 (if (= (type outlookapp) 'vla-object)
   (if ;; Create new courriel object
(setq mail_object (vlax-invoke-method outlookapp 'createitem 0))
     (if ;; Get the recipients collection
  (setq recipients_collection
  (vlax-get-property
    mail_object
    'recipients
  )
  )
(progn
  ;; Add the recipients properties to the courriel
  (foreach item recipients_list
    (if (= (type item) 'str)
      (vlax-invoke-method recipients_collection 'add item)
    )
  )
  ;; Add the subject properties to the courriel
  (if (= (type subject) 'str)
    (vlax-put-property mail_object 'subject subject)
  )
  ;; Add the body properties to the courriel
  (if (= (type body) 'str)
    (vlax-put-property mail_object 'body body)
  )
  ;; Add the attachements properties to the courriel
  (if (and (vl-consp attachments_list)
    (setq attachments_collection
    (vlax-get-property
      mail_object
      'attachments
    )
    )
      )
    (foreach item attachments_list
      (if
 (and (setq temp (findfile item)) (vl-file-systime temp))
  (vlax-invoke-method attachments_collection 'add temp)
      )
    )
  )
  ;; If the email_send equals 1 and the recipients_list, subject, and body were passed to the function then send the courriel, otherwise display the courriel for the user to finish
  (if (and (= email_send 1)
    (vl-consp recipients_list)
    subject
    body
    (/= subject "")
    (/= body "")
      )
    (vlax-invoke-method mail_object 'send)
    (vlax-invoke-method mail_object 'display)
  )
  (setq ret t)
)
(princ
  "\nCould not get the recipients collection from the new mail item"
)
     )
     (princ "\nCould not create a new mail item through Outlook")
   )
   (princ "\nCould not create a new instance of Outlook")
 )
 ;; Release the objects
 (if (and (= (type attachments_collection) 'vla-object)
   (= (vlax-object-released-p attachments_collection) nil)
     )
   (vlax-release-object attachments_collection)
 )
 (if (and (= (type recipients_collection) 'vla-object)
   (= (vlax-object-released-p recipients_collection) nil)
     )
   (vlax-release-object recipients_collection)
 )
 (if (and (= (type mail_object) 'vla-object)
   (= (vlax-object-released-p mail_object) nil)
     )
   (vlax-release-object mail_object)
 )
 (if (and (= (type outlookapp) 'vla-object)
   (= (vlax-object-released-p outlookapp) nil)
     )
   (vlax-release-object outlookapp)
 )
 (if (and (= (type acaddoc) 'vla-object)
   (= (vlax-object-released-p acaddoc) nil)
     )
   (vlax-release-object acaddoc)
 )
 (if (and (= (type acadapp) 'vla-object)
   (= (vlax-object-released-p acadapp) nil)
     )
   (vlax-release-object acadapp)
 )
 (princ)
 ret
)

Posté(e)

Salut,

 

Peut-être comme-ça (pas testé) :

   ;; Add the body properties to the courriel
  (if (= (type body) 'str)
    (progn
      (vlax-put-property mail_object 'BodyFormat olFormatPlain)
      ;; ou (vlax-put-property mail_object 'BodyFormat 1)
      (vlax-put-property mail_object 'Body body)
    )
  )

Gilles Chanteau - gileCAD - GitHub
Développements sur mesure pour AutoCAD

Posté(e)

Sans vouloir abuser, une autre question sur ce Lisp :

il est indiqué :

 ;(create-courriel recipients_list subject body attachments_list 1)
    ; Do send this mail immediately
 (create-courriel recipients_list subject body attachments_list 0) ; Do not yet send this mail

 

Mais l'un ou l'autre ne font pas l'envoie du mail immédiatement.

Comment faire l’envoie sans l’affichage du mail ?

Créer un compte ou se connecter pour commenter

Vous devez être membre afin de pouvoir déposer un commentaire

Créer un compte

Créez un compte sur notre communauté. C’est facile !

Créer un nouveau compte

Se connecter

Vous avez déjà un compte ? Connectez-vous ici.

Connectez-vous maintenant
×
×
  • Créer...

Information importante

Nous avons placé des cookies sur votre appareil pour aider à améliorer ce site. Vous pouvez choisir d’ajuster vos paramètres de cookie, sinon nous supposerons que vous êtes d’accord pour continuer. Politique de confidentialité