TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on December 08, 2010, 11:01:14 AM

Title: lisp to email
Post by: andrew_nao on December 08, 2010, 11:01:14 AM
anyone have any code or a method of bypass they can share that will send email messages without a warning from outlook or user interaction?

i have some code but when its activated i get this message from my outlook that is saying "a program is sending an email on your behalf bla bla bla... do you wish to continue"

and im trying to get around this and automatically send without user interaction

here is the code im using
Code: [Select]
(defun email ()
         (setq olApp (vlax-get-or-create-object "Outlook.Application"))
         (setq objMail (vlax-invoke olApp 'CreateItem 0))
         (vlax-put-property objMail 'Subject "subject here")
         (vlax-put-property objMail 'To "email here")   ;<-----specified email
         (vlax-put-property objMail 'Body "message here")

         (vlax-invoke objMail 'Send)
)

thanks
Title: Re: lisp to email
Post by: cmwade77 on December 08, 2010, 12:00:05 PM
Unfortunately, I do not; however, I would also be interested in this.....could do some automatic bug reports, as well as get a better idea of how users are using the routines.
Title: Re: lisp to email
Post by: ronjonp on December 08, 2010, 12:09:16 PM
This is pretty similar to what you are using (except you can add attachments). I tested it and do not get a prompt to send the mail.
http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794
Title: Re: lisp to email
Post by: TimSpangler on December 08, 2010, 12:18:58 PM
This is pretty similar to what you are using (except you can add attachments). I tested it and do not get a prompt to send the mail.
http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794

I got the prompt with this Ron.  Maybe it is a security setting?

I am running Outlook '03 if that matters.
Title: Re: lisp to email
Post by: ronjonp on December 08, 2010, 01:09:35 PM
Perhaps the antivirus is not up to date. I have 2007 and when disabled gave the send warning.
There is also a checkbox Tools>>Trust Center>>Programmatic Access (Never warn about suspicious activity) that stopped the prompt.
http://office.microsoft.com/en-us/outlook-help/i-get-warnings-about-a-program-accessing-e-mail-address-information-or-sending-e-mail-on-my-behalf-HA001229943.aspx#BM3
Title: Re: lisp to email
Post by: andrew_nao on December 08, 2010, 01:24:42 PM
i was hoping there was a way around this my IT admin isnt going to turn off the security settings for this
Title: Re: lisp to email
Post by: andrew_nao on December 08, 2010, 01:46:37 PM
after much searching the net i found this...
it has to be setup to work for you with your smpt info and account name and passwords but its worth a try
as soon as I get ahold of my IT admin i will test this out but if someone else tests this out before i do report back and let us know if this works

Code: [Select]
; use (sendmail cRecip cSender cServer cUser cPass cSubject cMessage)
(defun SendMail (cRecip cSender cServer cUser cPass cSubject cMessage / iMsg iConf Flds fItem)
; create our CDO object
  (setq iMsg  (vlax-create-object "CDO.Message")
iConf (vlax-create-object "CDO.Configuration")
Flds  (vlax-get-property iConf 'Fields)
  ) ; setq

; configure the settings
  (setq
    fItem (vlax-get-property
    Flds
    'Item
    "http://schemas.microsoft.com/cdo/configuration/sendusing"
  )
  )
  (vlax-put-property FItem 'Value 2)
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/smtpserver"
)
  )
  (vlax-put-property FItem 'Value cServer)
; @@ SMTP SERVER
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
)
  )
  (vlax-put-property FItem 'Value 25)
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
)
  )
  (vlax-put-property FItem 'Value 5) ; smtp server timeout in seconds
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
)
  )
  (vlax-put-property FItem 'Value 1)
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/sendusername"
)
  )
  (vlax-put-property FItem 'Value cUser) ; @@ ACCOUNT
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/sendpassword"
)
  )
  (vlax-put-property FItem 'Value cPass) ; @@ PASSWORD
  (vlax-invoke-method Flds 'Update)

; Build HTML for message body.
  (setq strHTML "<HTML>"
strHTML (strcat strHTML "<HEAD>")
strHTML (strcat strHTML "</HEAD>")
strHTML (strcat strHTML "<BODY>")
strHTML (strcat strHTML cMessage)
strHTML (strcat strHTML "</BODY>")
strHTML (strcat strHTML "</HTML>")
  ) ; setq

; Apply the settings to the message.
  (vlax-put-property iMsg 'Configuration iConf)
  (vlax-put-property iMsg 'To cRecip)
  (vlax-put-property iMsg 'From cSender); @@ FROM ADDRESS
  (vlax-put-property iMsg 'Subject cSubject)
  (vlax-put-property iMsg 'HTMLBody strHTML)
  (vlax-invoke-method iMsg 'Send)

  (vlax-release-object iMsg)
  (vlax-release-object iConf)

  (princ)
) ; SendMail
Title: Re: lisp to email
Post by: cmwade77 on December 08, 2010, 02:01:21 PM
Can you please provide where you got this, so that proper credit can be given?
Title: Re: lisp to email
Post by: andrew_nao on December 08, 2010, 02:05:34 PM
when googling it linked me to the autodesk forums

but im affraid i dont know how to set this up
maybe one of you other master coders can inform me/us
on how to set this up?
Title: Re: lisp to email
Post by: alanjt on December 08, 2010, 02:06:46 PM
Ron, on your routine, I didn't receive a prompt, but I still have to press send in the new email document, or is this supposed to happen?
Title: Re: lisp to email
Post by: ronjonp on December 08, 2010, 02:13:27 PM
Ron, on your routine, I didn't receive a prompt, but I still have to press send in the new email document, or is this supposed to happen?

It should have just sent? What version of Outlook are you using?
Title: Re: lisp to email
Post by: alanjt on December 08, 2010, 02:14:26 PM
Ron, on your routine, I didn't receive a prompt, but I still have to press send in the new email document, or is this supposed to happen?

It should have just sent? What version of Outlook are you using?
'03 in win7
Title: Re: lisp to email
Post by: Keith™ on December 08, 2010, 02:18:20 PM
Ron, on your routine, I didn't receive a prompt, but I still have to press send in the new email document, or is this supposed to happen?

It should have just sent? What version of Outlook are you using?

From the usage in the file provided by Ron ..
Quote
;;Usage
(rjp-OutlookMessage
  ;;email address (multiple separated by semicolon)
  "johndoe@nowhere.com;johndoewife@nowhere.com"
  ;;Subject
  "Test Email"
  ;;Attachments as a list of strings
  '("C:\\test\\file1.txt" "C:\\test\\file2.txt" "C:\\test\\file3.txt")
  ;;Text in body of email
  "Nothing to read here :)"
 ;;nil will open email to edit...T will send email in the background
  nil
)


Check your syntax ...
Title: Re: lisp to email
Post by: ronjonp on December 08, 2010, 02:18:29 PM
Ron, on your routine, I didn't receive a prompt, but I still have to press send in the new email document, or is this supposed to happen?

It should have just sent? What version of Outlook are you using?
'03 in win7

Did you specify T for the last arg?
Title: Re: lisp to email
Post by: alanjt on December 08, 2010, 02:20:05 PM
Ron, on your routine, I didn't receive a prompt, but I still have to press send in the new email document, or is this supposed to happen?

It should have just sent? What version of Outlook are you using?
'03 in win7

Did you specify T for the last arg?
I'm retarded - didn't even notice that.  :ugly:
FYI, it also gives me the warning.

Title: Re: lisp to email
Post by: andrew_nao on December 08, 2010, 02:34:34 PM
Ron, on your routine, I didn't receive a prompt, but I still have to press send in the new email document, or is this supposed to happen?

It should have just sent? What version of Outlook are you using?
'03 in win7

Did you specify T for the last arg?
I'm retarded - didn't even notice that.  :ugly:
FYI, it also gives me the warning.



that the same message i get
and my IT guy wont be available till next week so im SOL with this other code till then :(
Title: Re: lisp to email
Post by: cmwade77 on December 08, 2010, 02:38:27 PM
after much searching the net i found this...
it has to be setup to work for you with your smpt info and account name and passwords but its worth a try
as soon as I get ahold of my IT admin i will test this out but if someone else tests this out before i do report back and let us know if this works

Code: [Select]
; use (sendmail cRecip cSender cServer cUser cPass cSubject cMessage)
(defun SendMail (cRecip cSender cServer cUser cPass cSubject cMessage / iMsg iConf Flds fItem)
; create our CDO object
  (setq iMsg  (vlax-create-object "CDO.Message")
iConf (vlax-create-object "CDO.Configuration")
Flds  (vlax-get-property iConf 'Fields)
  ) ; setq

; configure the settings
  (setq
    fItem (vlax-get-property
    Flds
    'Item
    "http://schemas.microsoft.com/cdo/configuration/sendusing"
  )
  )
  (vlax-put-property FItem 'Value 2)
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/smtpserver"
)
  )
  (vlax-put-property FItem 'Value cServer)
; @@ SMTP SERVER
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
)
  )
  (vlax-put-property FItem 'Value 25)
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
)
  )
  (vlax-put-property FItem 'Value 5) ; smtp server timeout in seconds
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
)
  )
  (vlax-put-property FItem 'Value 1)
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/sendusername"
)
  )
  (vlax-put-property FItem 'Value cUser) ; @@ ACCOUNT
  (setq fItem
(vlax-get-property
   Flds
   'Item
   "http://schemas.microsoft.com/cdo/configuration/sendpassword"
)
  )
  (vlax-put-property FItem 'Value cPass) ; @@ PASSWORD
  (vlax-invoke-method Flds 'Update)

; Build HTML for message body.
  (setq strHTML "<HTML>"
strHTML (strcat strHTML "<HEAD>")
strHTML (strcat strHTML "</HEAD>")
strHTML (strcat strHTML "<BODY>")
strHTML (strcat strHTML cMessage)
strHTML (strcat strHTML "</BODY>")
strHTML (strcat strHTML "</HTML>")
  ) ; setq

; Apply the settings to the message.
  (vlax-put-property iMsg 'Configuration iConf)
  (vlax-put-property iMsg 'To cRecip)
  (vlax-put-property iMsg 'From cSender); @@ FROM ADDRESS
  (vlax-put-property iMsg 'Subject cSubject)
  (vlax-put-property iMsg 'HTMLBody strHTML)
  (vlax-invoke-method iMsg 'Send)

  (vlax-release-object iMsg)
  (vlax-release-object iConf)

  (princ)
) ; SendMail
This works perfectly, I would like a link to where it was found though....I always try to put those in my LISP routines when I find something online.
Title: Re: lisp to email
Post by: Keith™ on December 08, 2010, 02:39:25 PM
Outlook -> Tools -> Trust Center -> Programmatic Access -> Never warn me about suspicious activity (not recommended)

Title: Re: lisp to email
Post by: andrew_nao on December 08, 2010, 02:45:48 PM
This works perfectly, I would like a link to where it was found though....I always try to put those in my LISP routines when I find something online.

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Email/m-p/1619391

can you post what you did so i can see how this works?
Title: Re: lisp to email
Post by: andrew_nao on December 08, 2010, 02:47:38 PM
Outlook -> Tools -> Trust Center -> Programmatic Access -> Never warn me about suspicious activity (not recommended)



i dont have trust center in my tools

im using outlook 2000 sp3
Title: Re: lisp to email
Post by: Keith™ on December 08, 2010, 02:48:43 PM
Perhaps it is disabled by the administrator OR it is under a securities tab in the options
Title: Re: lisp to email
Post by: cmwade77 on December 08, 2010, 02:56:21 PM
This works perfectly, I would like a link to where it was found though....I always try to put those in my LISP routines when I find something online.

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Email/m-p/1619391

can you post what you did so i can see how this works?

Here is how I called the routine (be sure to replace anything in <> with your information):
(sendmail "<To Email Address>" "<From Email Address>" "<SMTP Server>" "<UserName>" "<Password>" "Test Email" "This is a test from within AutoCAD!")

You will need an SMTP server that uses standard ports, you will also need to know your username and password for the SMTP server. Please note that Google's SMTP server will not work without modifications to the code; however, there are many free ones out there that will work.
Title: Re: lisp to email
Post by: JohnK on December 08, 2010, 04:08:25 PM

http://www.theswamp.org/index.php?topic=14646.msg176789#msg176789
Title: Re: lisp to email
Post by: andrew_nao on December 10, 2010, 04:40:55 PM
has anyone have any experience with using this on an ms exchange server
my email goes thru an exchange server and not a smtp server so this code isnt doing me any good.
Title: Re: lisp to email
Post by: JohnK on December 10, 2010, 05:35:31 PM
yes, me.

try: "mail.YourDomainName" or "mail.YourCompanyName"
Title: Re: lisp to email
Post by: andrew_nao on December 13, 2010, 09:45:02 AM
yes, me.

try: "mail.YourDomainName" or "mail.YourCompanyName"


i tried that but i get this error
; error: Automation Error. The transport lost its connection to the server.

would you know what this means?
Title: Re: lisp to email
Post by: JohnK on December 13, 2010, 10:41:44 AM
Sorry, i dont.