Author Topic: send mail with VLisp  (Read 571 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 724
send mail with VLisp
« on: February 01, 2024, 10:52:32 AM »
send mail with VLisp ...

is it possible ?

I found something in theswamp, but:

(setq oa-obj (vlax-get-or-create-object "Outlook.Application"))   >   NIL !

why?


PKENEWELL

  • Bull Frog
  • Posts: 317
Re: send mail with VLisp
« Reply #1 on: February 01, 2024, 12:18:56 PM »
Here is Some Code by Alan J. Thomson from the forum. I don't remember the where original posting was:
Code - Auto/Visual Lisp: [Select]
  1. ;; =========ENTER the Email Addresses Here as Strings!=================!
  2. (setq *IT-Email* "someITguy@somecompany.com"
  3.       *CC-Email* "myAddress@MyCompany"
  4.       *MsgString* "This is a Test Message."
  5. )
  6. ;;=====================================================================
  7.  
  8.  
  9. (defun c:CRGhelp (/ _catch cc file outlook email sf si ni)
  10.   ;; Using Outlook, eMail selected object(s) in a temporary DWG file
  11.   ;; Many thanks to Ron Perez (ronjonp) for the Outlook example (http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794)
  12.   ;; Alan J. Thompson, 03.28.11
  13.  
  14.  
  15.   (defun _catch (f a) (not (vl-catch-all-error-p (vl-catch-all-apply f a))))
  16.  
  17.   (alert "After you choose your parts. Remember to send the file from outlook")
  18.  
  19.   (if
  20.     (and
  21.       (or (ssget "_I") (prompt "\nSelect object(s) to eMail: ") (ssget))
  22.       (setq file (vl-filename-mktemp "" nil ".dwg") test (princ (strcat "\n" file)))
  23.       (_catch 'vla-WBlock
  24.               (list (cond (*AcadDoc*)
  25.                           ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
  26.                     )
  27.                     file
  28.                     (vla-get-activeselectionset *AcadDoc*)
  29.               )
  30.       )
  31.       (setq outlook (vlax-get-or-create-object "Outlook.Application")
  32.             sf (vl-catch-all-apply 'vlax-invoke (list (setq ns (vlax-invoke outlook 'GetNameSpace "MAPI")) 'GetDefaultFolder 5))
  33.             si (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count))
  34.       )
  35.       (setq email (vlax-invoke-method outlook 'CreateItem 0))
  36.       (_catch 'vlax-put (list email 'Subject (strcat "Autocad help: " (vl-filename-base file) ".dwg")))
  37.       (_catch 'vlax-invoke (list (vlax-get email 'Attachments) 'Add file))
  38.       (_catch 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *IT-Email*))
  39.       (setq cc (vl-catch-all-apply 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *CC-Email*)))
  40.       (_catch 'vlax-put (list cc 'Type 2))
  41.       (_catch 'vlax-put (list email 'Body *MsgString*))
  42.     )
  43.      (progn (princ "\nOutlook active...")
  44.             (princ)
  45.             (vlax-invoke email 'Display :vlax-true)
  46.             (if (= (vl-catch-all-apply 'vlax-get (list email 'Sent)) :vlax-true)
  47.                (vl-file-delete file)
  48.                (progn
  49.                    (if (= (setq ni (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count))) si)
  50.                        (vl-file-delete file); No email was added to Sent Items - go ahead and delete.
  51.                    )
  52.                )
  53.             )
  54.      )
  55.   )
  56.   (foreach x (list sf ns email outlook) (and x (vlax-release-object x)))
  57.   (princ)
  58. )
  59.  
"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

domenicomaria

  • Swamp Rat
  • Posts: 724
Re: send mail with VLisp
« Reply #2 on: February 01, 2024, 12:20:38 PM »
yes ...
but my problem is :

(setq outlook (vlax-get-or-create-object "Outlook.Application") )   >  NIL  ! ! !

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: send mail with VLisp
« Reply #3 on: February 01, 2024, 01:42:57 PM »
yes ...
but my problem is :

(setq outlook (vlax-get-or-create-object "Outlook.Application") )   >  NIL  ! ! !

Is a local Outlook Installed, or are you using the web version? The above method won't work if you are just using Outlook through your browser.
"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

domenicomaria

  • Swamp Rat
  • Posts: 724
Re: send mail with VLisp
« Reply #4 on: February 01, 2024, 02:50:44 PM »
Is a local Outlook Installed?

Yes

Lonnie

  • Newt
  • Posts: 175
Re: send mail with VLisp
« Reply #5 on: February 01, 2024, 03:49:10 PM »
Don't know if it helps but this worked for me.

https://www.theswamp.org/index.php?topic=55486.0;all

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: send mail with VLisp
« Reply #6 on: February 01, 2024, 05:00:08 PM »
Is a local Outlook Installed?

Yes

Maybe try changing the string to "Outlook.Application.16"? Otherwise I am not sure what's going on.
"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

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: send mail with VLisp
« Reply #7 on: February 01, 2024, 06:16:39 PM »
Could it be that Outlook is still 32 bit, haven't use outlook in like forever?

kozmos

  • Newt
  • Posts: 114
Re: send mail with VLisp
« Reply #8 on: February 01, 2024, 08:42:28 PM »
if your email can be sent via curl, then you can use vlisp to call curl doing it. no outlook is needed
KozMos Inc.

domenicomaria

  • Swamp Rat
  • Posts: 724
Re: send mail with VLisp
« Reply #9 on: February 01, 2024, 10:08:16 PM »
if your email can be sent via curl, then you can use vlisp to call curl doing it. no outlook is needed

How do you do ?
can you give me an example?

domenicomaria

  • Swamp Rat
  • Posts: 724
Re: send mail with VLisp
« Reply #10 on: February 01, 2024, 10:10:32 PM »
Maybe try changing the string to "Outlook.Application.16"? Otherwise I am not sure what's going on.

(setq outlook (vlax-get-or-create-object "Outlook.Application.16")) > nil

domenicomaria

  • Swamp Rat
  • Posts: 724
Re: send mail with VLisp
« Reply #11 on: February 01, 2024, 10:14:40 PM »
Could it be that Outlook is still 32 bit, haven't use outlook in like forever?

I have always only used GMail

if I search for "outlook"
I get "outlook(new)" which is probably just a web app...

EWCAD

  • Mosquito
  • Posts: 14
Re: send mail with VLisp
« Reply #12 on: February 02, 2024, 07:47:09 AM »
Non Visual solution but this is a bit of code I wrote to attach printed PDF's to an email with a subject and recipient in outlook. It just calls outlook.exe and uses the command line arguments built into it. They have pretty good documentation regarding the different arguments you can use. You would want to obviously replace the variables I'm using in the strcat to whatever suits your needs.

Code: [Select]
(setq outlook "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\OUTLOOK.EXE") ;Change to YOUR Outlook installation directory
(startapp (strcat (chr 34) outlook (chr 34) "/c ipm.note /a " (chr 34) trgfile (chr 34) "/m "(chr 34) "mailto:" recipient "?subject=" customer " - " (strcat dwgname rev#) "&body="(chr 34)))

This won't automatically hit send, but it will open the email and fill out all the fields or attach files so that all you have to do manually is click 1 button.

domenicomaria

  • Swamp Rat
  • Posts: 724
Re: send mail with VLisp
« Reply #13 on: February 02, 2024, 08:28:45 AM »
everything is solved...!
Outlook simply wasn't installed on the PC!
  :embarrassed2: :grumpy: :lol:

I apologize ...
but the PC where I work is not mine
and they assured me that the entire Office package was installed!

And I didn't even check!

 :whistling: