Author Topic: Lisp to e-mail content to helpdesk.  (Read 1130 times)

0 Members and 1 Guest are viewing this topic.

Lonnie

  • Mosquito
  • Posts: 17
Lisp to e-mail content to helpdesk.
« on: October 10, 2019, 04:03:30 PM »
Full disclosure I am on the Autodesk site with this <a href="https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-e-mail-content-to-helpdesk/td-p/9077327">post</a>.


I have tried once or 100 times to edit this and I don't get the results I want.


Ideally This would autofill

1.  Subject name. (Subject)

2. Captures a dwg of the area someone is having a problem with this routine works exactly like I want it to for this portion. (attachment)

3. Then sends it to me. (To)

All my people would need to do is

Type a little explanation of what's going wrong (Body) in a window that is magically provided to them. (Scratch text file)
then
choose the objects they want for the dwg file.

Your Routine

Launches a mail

Attaches a dwg (GREAT!!)

Gives a Subject. ( I was able to add the file name and path to subject.)


and waits for the user to add the

to and body.


I have also looked at the post this routine referenced that adds a text file as an attachment.
would it be possible to edit the text file then  add that file in the body of the e-mail and send the file on it's way?

I know I am asking a lot and I am willing to do the work. It's just that much above the level I unserstand.


Thank you in advance.

Lonnie
lisp rountine.

Code - Auto/Visual Lisp: [Select]
  1. ;;Call IT
  2.  
  3.  
  4. (defun c:CRGhelp (/ _catch file outlook email)
  5.   ;; Using Outlook, eMail selected object(s) in a temporary DWG file
  6.   ;; Many thanks to Ron Perez (ronjonp) for the Outlook example (http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794)
  7.   ;; Alan J. Thompson, 03.28.11
  8.  
  9.  
  10.   (defun _catch (f a) (not (vl-catch-all-error-p (vl-catch-all-apply f a))))
  11. (alert "After you choose your parts. Remember to send the file from outlook
  12. ")
  13.   (if
  14.     (and
  15.       (or (ssget "_I") (prompt "\nSelect object(s) to eMail: ") (ssget))
  16.       (setq file (vl-filename-mktemp "" nil ".dwg"))
  17.       (_catch 'vla-WBlock
  18.               (list (cond (*AcadDoc*)
  19.                           ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
  20.                     )
  21.                     file
  22.                     (vla-get-activeselectionset *AcadDoc*)
  23.               )
  24.       )
  25.       (setq outlook (vlax-get-or-create-object "Outlook.Application"))
  26.       (setq email (vlax-invoke-method outlook 'CreateItem 0))
  27.       (_catch 'vlax-put (list email 'Subject (strcat "Autocad help: " (vl-filename-base file) ".dwg")))
  28.       (_catch 'vlax-invoke (list (vlax-get email 'Attachments) 'Add file))
  29.     )
  30.      (progn (princ "\nOutlook active...")
  31.             (princ)
  32.             (vlax-invoke email 'Display :vlax-true)
  33.             (vl-file-delete file)
  34.      )
  35.   )
  36.   (foreach x (list email outlook) (and x (vlax-release-object x)))
  37.   (princ)
  38. )


EDIT (John): added code tags for better formatting.


« Last Edit: October 14, 2019, 09:37:20 AM by John Kaul (Se7en) »

PKENEWELL

  • Bull Frog
  • Posts: 228
Re: Lisp to e-mail content to helpdesk.
« Reply #1 on: October 11, 2019, 03:11:47 PM »
Give This lisp file a try. I determined the other objects you need to fill in the email.

NOTE:
1) You need to fill in the global variables at the top of the LISP file with the info you want (TO Recipient, CC Recipient, Default Message). For the message - alternately you can read in a text file.
2) I don't think you can delete the file without determining if the email sent, so I added in a check to see if the email sent before deleting. If the email was discarded, the program checks the sent items count and will delete the file if it did not change.

P.S: If you want to look more into the Outlook ActiveX Methods and properties, This reference will get you started: https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem
« Last Edit: October 11, 2019, 05:02:16 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

Lonnie

  • Mosquito
  • Posts: 17
Re: Lisp to e-mail content to helpdesk.
« Reply #2 on: October 11, 2019, 05:08:29 PM »
 
I should be able to get this a lot further along now.

Thank you so much for the help.

PKENEWELL

  • Bull Frog
  • Posts: 228
Re: Lisp to e-mail content to helpdesk.
« Reply #3 on: October 11, 2019, 05:29:35 PM »

I should be able to get this a lot further along now.

Thank you so much for the help.

No problem - It was actually a fun exercise and useful learning for myself as well.  :-D
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

HasanCAD

  • Swamp Rat
  • Posts: 1308
Re: Lisp to e-mail content to helpdesk.
« Reply #4 on: October 14, 2019, 03:43:01 AM »
Some PCs connected directly to internet but does not have Outlook.
I am wondering, Is it able to send email without Outlook?!

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9277
Re: Lisp to e-mail content to helpdesk.
« Reply #5 on: October 14, 2019, 09:35:57 AM »
Some PCs connected directly to internet but does not have Outlook.
I am wondering, Is it able to send email without Outlook?!

I don't think Microsoft has built in SMTP support (Microsoft Server may though) so you need some sort of mail program.  But at any rate, you'd need a login to your exchange service. In a pinch, I used the exchange server credentials of a copier in the office to send out mail.

You could use a small command line based email program like Pine, or Mutt. So, in other words, you can display the message in a nice custom format/window and then just use the CLI email program to fire off the message.
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

Lonnie

  • Mosquito
  • Posts: 17
Re: Lisp to e-mail content to helpdesk.
« Reply #6 on: October 14, 2019, 02:47:06 PM »
next problem.
Everything works great. EXCEPT Ain't there always one of those.
I added a few things in my body. One of which is a line to tell me what file they are in.

Code - Auto/Visual Lisp: [Select]
  1. *Fileset1* (strcat "Example file from" "\n" "\""(getvar "dwgprefix") (getvar "dwgname")"\"" "\nPlease tell me what's wrong")

This works until you get a space in the pathname. Once you do you break the link. As you see I tried to add quotes around the string but that did not work.
Does anyone know a way to get mail to send the whole url if it's got special characters?


Code - Auto/Visual Lisp: [Select]
  1. ;; Using Outlook, eMail selected object(s) in a temporary DWG file
  2. ;; Many thanks to Ron Perez (ronjonp) for the Outlook example (http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794)
  3. ;; Alan J. Thompson, 03.28.11
  4. ;;Call IT
  5.  
  6.  
  7. ;; =========ENTER the Email Addresses Here as Strings!=================!
  8. (setq *IT-Email* "somedude.NET"
  9.       *CC-Email* "sumotherdude.NET"
  10.       *Fileset1* (strcat "Example file from" "\n" "\""(getvar "dwgprefix") (getvar "dwgname")"\"" "\nPlease tell me what's wrong")
  11. )
  12. ;;=====================================================================
  13.  
  14.  
  15. (defun c:CRGhelp (/ _catch cc file outlook email sf si ni)
  16.  
  17.  
  18.   (defun _catch (f a) (not (vl-catch-all-error-p (vl-catch-all-apply f a))))
  19.  
  20.   (alert "After you select object to mail remember to send from outlook")
  21.  
  22.   (if
  23.     (and
  24.       (or (ssget "_I") (prompt "\nSelect object(s) to eMail: ") (ssget))
  25.       (setq file (vl-filename-mktemp "" nil ".dwg") test (princ (strcat "\n" file)))
  26.       (_catch 'vla-WBlock
  27.               (list (cond (*AcadDoc*)
  28.                           ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
  29.                     )
  30.                     file
  31.                     (vla-get-activeselectionset *AcadDoc*)
  32.               )
  33.       )
  34.       (setq outlook (vlax-get-or-create-object "Outlook.Application")
  35.             sf (vl-catch-all-apply 'vlax-invoke (list (setq ns (vlax-invoke outlook 'GetNameSpace "MAPI")) 'GetDefaultFolder 5))
  36.             si (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count))
  37.       )
  38.       (setq email (vlax-invoke-method outlook 'CreateItem 0))
  39.       (_catch 'vlax-put (list email 'Subject (strcat "Autocad help: " (vl-filename-base file) ".dwg")))
  40.       (_catch 'vlax-invoke (list (vlax-get email 'Attachments) 'Add file))
  41.       (_catch 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *IT-Email*))
  42.       (setq cc (vl-catch-all-apply 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *CC-Email*)))
  43.       (_catch 'vlax-put (list cc 'Type 2))
  44.       (_catch 'vlax-put (list email 'Body *Fileset1* ))
  45.     )
  46.      (progn (princ "\nOutlook active...")
  47.             (princ)
  48.             (vlax-invoke email 'Display :vlax-true)
  49.             (if (= (vl-catch-all-apply 'vlax-get (list email 'Sent)) :vlax-true)
  50.                (vl-file-delete file)
  51.                (progn
  52.                    (if (= (setq ni (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count))) si)
  53.                        (vl-file-delete file); No email was added to Sent Items - go ahead and delete.
  54.                    )
  55.                )
  56.             )
  57.      )
  58.   )
  59.   (foreach x (list sf ns email outlook) (and x (vlax-release-object x)))
  60.   (princ)
  61. )
  62.  


EDIT (John): Added code tags for readability.
« Last Edit: October 14, 2019, 04:41:26 PM by John Kaul (Se7en) »

MP

  • Seagull
  • Posts: 17479
Re: Lisp to e-mail content to helpdesk.
« Reply #7 on: October 14, 2019, 02:53:18 PM »
You can replace spaces in urls with %20. If you mean a path with spaces enclose it in double quotes.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Lonnie

  • Mosquito
  • Posts: 17
Re: Lisp to e-mail content to helpdesk.
« Reply #8 on: October 14, 2019, 03:05:25 PM »
That's what I thought I was doing with the "\""
"\\DavWWWRoot\revit\revitblog\PublishingImages\New user Packet\Drawing2.dwg"

I expected it to give me just the url like it will when I type it in.
« Last Edit: October 14, 2019, 03:10:29 PM by Lonnie »

MP

  • Seagull
  • Posts: 17479
Re: Lisp to e-mail content to helpdesk.
« Reply #9 on: October 14, 2019, 05:20:23 PM »
If that's intended to be a unc path it should likely be:

"\"\\\\DavWWWRoot\\revit\\revitblog\\PublishingImages\\New user Packet\\Drawing2.dwg\""
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17479
Re: Lisp to e-mail content to helpdesk.
« Reply #10 on: October 14, 2019, 05:31:54 PM »
Some PCs connected directly to internet but does not have Outlook.
I am wondering, Is it able to send email without Outlook?!

If you know the name of your smtp server etc ...

Code: [Select]
(defun _send-email ( from to subject body attachment / :put :eval :main )

    ;;  see: https://docs.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2003/ms877946(v=exchg.65)

    ;;  (_send-email
    ;;      "ice-queen@hiding-at-undisclosed-location.com"
    ;;      "agent-orange@deranged-and-dangerous.com"
    ;;      "I had a wonderful dream of the single life ..."
    ;;      "... only to wake and find I was still with you IRL.\n\nOMG."
    ;;      "c:\\picture-of-large-soured-pumpkin.png"
    ;;  )
   
    (setq :eval
        (lambda ( statement )
            (vl-catch-all-apply 'eval
                (list statement)
            )
        )
    )

    (setq :put
        (lambda ( object key value / result )
            (:eval
               '(progn
                    (setq result
                        (vlax-put-property
                            (vlax-get-property object 'item key)
                           'value
                            value
                        )
                    )
                    (if result result t)
                )
            )
        )
    )
   
    (defun :main ( from to subject body attach / server-name server-port using-port cdo server result path )

        (setq
            server-name "mail.your-legit-server.com"
            server-port 25
            using-port  2
            cdo         (vlax-create-object "CDO.Message")
            server      (vlax-get-property (vlax-get-property cdo 'configuration) 'fields)
        )

        (:eval

           '(progn

                (:put server "http://schemas.microsoft.com/cdo/configuration/sendusing"      using-port)
                (:put server "http://schemas.microsoft.com/cdo/configuration/smtpserver"     server-name)
                (:put server "http://schemas.microsoft.com/cdo/configuration/smtpserverport" server-port)

                (vlax-invoke server 'update)
                (vlax-put-property cdo 'from     from)
                (vlax-put-property cdo 'to       to)
                (vlax-put-property cdo 'subject  subject)
                (vlax-put-property cdo 'textbody body)

                (and
                    (eq 'str (type attach))
                    (setq path (findfile attach))
                    (:eval '(vlax-invoke cdo 'addattachment attach))
                )

                (setq result (vlax-invoke cdo 'send))
                (setq result (if result result t))
            )
        )

        (:eval '(vlax-release-object server))
        (:eval '(vlax-release-object cdo))

        result
       
    )
   
    (:main from to subject body attachment)       

)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Lonnie

  • Mosquito
  • Posts: 17
Re: Lisp to e-mail content to helpdesk.
« Reply #11 on: October 14, 2019, 06:12:28 PM »
That will still break on that first space. I've triad quite a few different approaches including file:/// nothing will work html and plain text.

It's a little harder than I thought. I can make it plain text then copy paste it to my autocad. That's not a bad solution.
Thanks for all the help everyone.!!!
this place is great. I promise I will return more than once every 2 years.

If that's intended to be a unc path it should likely be:

"\"\\\\DavWWWRoot\\revit\\revitblog\\PublishingImages\\New user Packet\\Drawing2.dwg\""
« Last Edit: October 14, 2019, 06:15:35 PM by Lonnie »

MP

  • Seagull
  • Posts: 17479
Re: Lisp to e-mail content to helpdesk.
« Reply #12 on: October 14, 2019, 06:24:00 PM »
It will or it did?
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Lonnie

  • Mosquito
  • Posts: 17
Re: Lisp to e-mail content to helpdesk.
« Reply #13 on: October 14, 2019, 06:51:58 PM »
did sorry.

I should modify the "Did not work" a little what you had will work may work for my example.
I reality I am getting the unc from "dwgprefix"  "dwgname". That's what did not work.  For every try I did something else seemed to happen.

I am extremely happy with these results. Thank you all.

« Last Edit: October 14, 2019, 07:01:08 PM by Lonnie »

MP

  • Seagull
  • Posts: 17479
Re: Lisp to e-mail content to helpdesk.
« Reply #14 on: October 14, 2019, 08:34:34 PM »
If you're getting the path-name from dwgprefix and dwgname I'd be surprised this wouldn't work:

Code: [Select]
(defun _get-my-full-name ( )
    (   (lambda ( fn )
            (if (wcmatch fn "* *")
                (strcat "\"" fn "\"")
                fn
            )               
        )
        (apply 'strcat (mapcar 'getvar '(dwgprefix dwgname)))
    )
)

What does (_get-my-full-name) return on your machine?
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox