I should be able to get this a lot further along now.
Thank you so much for the help.
Some PCs connected directly to internet but does not have Outlook.
I am wondering, Is it able to send email without Outlook?!
Some PCs connected directly to internet but does not have Outlook.
I am wondering, Is it able to send email without Outlook?!
(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)
)
If that's intended to be a unc path it should likely be:
"\"\\\\DavWWWRoot\\revit\\revitblog\\PublishingImages\\New user Packet\\Drawing2.dwg\""
(defun _get-my-full-name ( )
( (lambda ( fn )
(if (wcmatch fn "* *")
(strcat "\"" fn "\"")
fn
)
)
(apply 'strcat (mapcar 'getvar '(dwgprefix dwgname)))
)
)
...
If you know the name of your smtp server etc ...Code - Auto/Visual Lisp: [Select]
... (setq server-name "mail.your-legit-server.com" server-port 25 using-port 2 ) ...
Question: does port 25 still work (I mean, I thought port 25 was blocked now-a-days)? Good if it does, I guess.
This is what you get when you look at the html string that gets sent with the original suggestion.
Question: does port 25 still work (I mean, I thought port 25 was blocked now-a-days)? Good if it does, I guess.
I've been successfully using the code I posted for years - it's still in place, functioning. That said, it really depends upon your mail server - recommend one talks to their IT folks for the sendusing, smtpserver & smtpserverport configuration values (lines 52-54 in the code I posted).This is what you get when you look at the html string that gets sent with the original suggestion.
Good gawd, yet another reason NOT to use outlook. That is horrendous, polluted sh@t.
I was just questioning port 25.
Yeah, that's outlook/html email for you; messy stuff. :) You can change your settings to Plain text and get cleaner results.
"C:\\Users\\lshaw\\Documents\\Drawing1.dwg"
You're so picky.
"\"\\\\dce\\boi\\Projects\\2018 Jobs\\18PAC01 - Garden Brook Senior Village - Garden Grove, CA\\Cadd\\Apartments\\18PAC01-M215.dwg\""
(_send-email ;; see pickey email thread: http://bit.ly/2BfbU2g
(_get-users-email-addy) ;; do-able via active directory
(_get-help-desk-email-addy) ;; a constant you would provide
(_get-email-subject) ;; either hard coded or via some input method
(_get-email-body) ;; either hard coded or via some input method
(_get-my-full-name) ;; see pickey email thread: http://bit.ly/2BfbU2g
)
(defun _get-users-email-addy ( / network user domain conn qry ldaprs fld result )
(vl-catch-all-apply
'(lambda ( )
(setq
network (vlax-create-object "Wscript.Network")
user (vlax-get network 'username)
domain (vlax-get network 'userdomain)
conn (vlax-create-object "ADODB.Connection")
)
(vlax-put conn 'provider "ADsDSOObject")
(vlax-invoke conn 'open "ADSI")
(setq
qry (strcat "select mail from 'LDAP://" domain "' ")
qry (strcat qry "WHERE objectClass = 'user' and ")
qry (strcat qry "samAccountName = '" user "'")
ldaprs (vlax-invoke conn 'execute qry)
fld (vlax-invoke (vlax-get ldaprs 'fields) 'item "mail")
result (vlax-get fld 'value)
)
)
)
(vl-catch-all-apply 'vlax-release-object (list fld))
(vl-catch-all-apply 'vlax-release-object (list ldaprs))
(vl-catch-all-apply 'vlax-release-object (list conn))
(vl-catch-all-apply 'vlax-release-object (list network))
(if (eq 'str (type result)) result)
)
Regarding _get-users-email-addy the following should work (I say should because I just translated it from vb and I'm not on an active directory network at home so I can't test it). Would be great if someone could verify if it works or not, thanks.Code: [Select](defun _get-users-email-addy ( / network user domain conn qry ldaprs fld result )
(vl-catch-all-apply
'(lambda ( )
(setq
network (vlax-create-object "Wscript.Network")
user (vlax-get network 'username)
domain (vlax-get network 'userdomain)
conn (vlax-create-object "ADODB.Connection")
)
(vlax-put conn 'provider "ADsDSOObject")
(vlax-invoke conn 'open "ADSI")
(setq
qry (strcat "select mail from 'LDAP://" domain "' ")
qry (strcat qry "WHERE objectClass = 'user' and ")
qry (strcat qry "samAccountName = '" user "'")
ldaprs (vlax-invoke conn 'execute qry)
fld (vlax-invoke (vlax-get ldaprs 'fields) 'item "mail")
result (vlax-get fld 'value)
)
)
)
(vl-catch-all-apply 'vlax-release-object (list fld))
(vl-catch-all-apply 'vlax-release-object (list ldaprs))
(vl-catch-all-apply 'vlax-release-object (list conn))
(vl-catch-all-apply 'vlax-release-object (list network))
(if (eq 'str (type result)) result)
)
(_get-users-email-addy) >> yourname@yourdomain.com
Cheers.
(defun _get-users-email-addy (/ network user domain conn qry ldaprs fld result)
(setq result nil) ; Initialize result to nil
(vl-catch-all-apply
'(lambda ()
(setq
network (vlax-create-object "Wscript.Network")
user (vlax-get network 'username)
domain (vlax-get network 'userdomain)
conn (vlax-create-object "ADODB.Connection")
)
(vlax-put conn 'provider "ADsDSOObject")
(vlax-invoke conn 'open "ADSI")
(setq
qry (strcat "select mail from 'LDAP://" domain "' ")
qry (strcat qry "WHERE objectClass = 'user' and ")
qry (strcat qry "samAccountName = '" user "'")
)
(princ (strcat "\nLDAP Query: " qry)) ; Print the LDAP query for debugging
(setq ldaprs (vlax-invoke conn 'execute qry))
(setq fld (vlax-invoke (vlax-get ldaprs 'fields) 'item "mail"))
(setq result (vlax-get fld 'value))
)
)
(if (eq 'str (type result))
(progn
(princ (strcat "\nEmail Address: " result)) ; Print the result for debugging
result
)
(progn
(princ "\nFailed to retrieve email address.")
nil
)
)
)
;; Call IT Helpdesk Script
;; Using Outlook, this script will email selected objects in a temporary DWG file.
;; Credits to Ron Perez (ronjonp) for the Outlook example:
;; http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794
;; http://www.theswamp.org/index.php?topic=55486.0
;; Lonnie Shaw 2020-01-06
;; Enter the Email Addresses Here as Strings
(setq *IT-Email* "lshaw@coname.net"
*CC-Email* "bsmead@coname.net"
*BCC-Email* "bseverson@coname.net; dsmith@coname.net; tmcauley@coname.net; jnewton@coname.net; pwyman@coname.net; rstock@coname.net; jarreola@coname.net"
*Fileset1* (strcat "\nI need assistance from a CAD area Lead. Thank you!"
"\nExample file from"
"\n" (getvar "dwgprefix")
"\"" (getvar "dwgname") "\"")
)
(defun c:CRGhelp (/ _catch cc file outlook email sf si ni)
;; Load the Visual LISP extension
(vl-load-com)
;; Define a helper function to catch errors
(defun _catch (f a) (not (vl-catch-all-error-p (vl-catch-all-apply f a))))
;; Alert the user to select objects and send mail from Outlook
(alert "Please create a scratch file by selecting the elements you are having problems with. \n\nAfter you select objects to mail, remember to send mail from Outlook.")
(if
(and
;; Get selected objects
(or (ssget "_I") (prompt "\nSelect object(s) to eMail: ") (ssget))
;; Create a temporary DWG file
(setq file (vl-filename-mktemp "" nil ".dwg"))
(_catch 'vla-WBlock
(list (cond (*AcadDoc*)
((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))))
file
(vla-get-activeselectionset *AcadDoc*)))
;; Create an Outlook application instance
(setq outlook (vlax-get-or-create-object "Outlook.Application"))
(setq sf (vl-catch-all-apply 'vlax-invoke (list (setq ns (vlax-invoke outlook 'GetNameSpace "MAPI")) 'GetDefaultFolder 5)))
(setq si (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count)))
;; Create a new email item
(setq email (vlax-invoke-method outlook 'CreateItem 0))
;; Set email subject
(_catch 'vlax-put (list email 'Subject "Helpdesk Ticket: "))
;; Attach the temporary DWG file
(_catch 'vlax-invoke (list (vlax-get email 'Attachments) 'Add file))
;; Add recipients
(_catch 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *IT-Email*))
(setq cc (vl-catch-all-apply 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *CC-Email*)))
(setq bcc (vl-catch-all-apply 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *BCC-Email*)))
;; Set recipient types
(_catch 'vlax-put (list cc 'Type 2)) ;; CC
(_catch 'vlax-put (list bcc 'Type 3)) ;; BCC
;; Set the email body
(_catch 'vlax-put (list email 'Body *Fileset1*))
)
;; Display the email in Outlook and handle file cleanup
(progn
(princ "\nOutlook active...")
(vlax-invoke email 'Display :vlax-true)
(if (= (vl-catch-all-apply 'vlax-get (list email 'Sent)) :vlax-true)
(vl-file-delete file)
(progn
(if (= (setq ni (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count))) si)
(vl-file-delete file) ;; No email was added to Sent Items - delete the file
)
)
)
)
)
;; Release COM objects
(foreach x (list sf ns email outlook) (and x (vlax-release-object x)))
(princ)
)