Author Topic: Syntax for email  (Read 11180 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Syntax for email
« on: January 23, 2007, 02:31:04 AM »
Hi Alls,
That code I got from a forum,if that code load ,in column "cc" and "attachment" still blank,what wrong in syntax?.
Code: [Select]
(setq mail
   (strcat
      "mailto:adesu@telkom.net"
      "ccto=adesu_cad@yahoo.com"  ; still problem
      "?Subject=test send email via autolisp"
      "&body=This email has been sended by autolisp"
      "&attachment=\"D:\\Attention.eml\""   ; still problem
))
(setq Ishell
   (vla-GetInterfaceObject
      (vlax-get-acad-object)
      "Shell.Application"))
(vlax-invoke-method Ishell 'OPEN mail)
(vlax-release-object Ishell)

Patrick_35

  • Guest
Re: Syntax for email
« Reply #1 on: January 23, 2007, 03:09:29 AM »

Adesu

  • Guest
Re: Syntax for email
« Reply #2 on: January 23, 2007, 03:23:38 AM »
I just revised that code,but attach file still not yet display,any idea
Code: [Select]
(setq mail
   (strcat
      "mailto:adesu@telkom.net"
      "?cc=adesu_cad@yahoo.com"
      "&Subject=test send email via autolisp"
      "&body=This email has been sended by autolisp"
      "&attachment=(findfile \"D:\\YBI\\Drawing\\Lat\\2 D\\gear.dwg\")" ; still problem
      ))
(setq Ishell
   (vla-GetInterfaceObject
      (vlax-get-acad-object)
      "Shell.Application"))
(vlax-invoke-method Ishell 'OPEN mail)
(vlax-release-object Ishell)

Adesu

  • Guest
Re: Syntax for email
« Reply #3 on: January 23, 2007, 03:40:46 AM »
Look at attach file,I want like that

Patrick_35

  • Guest
Re: Syntax for email
« Reply #4 on: January 23, 2007, 03:49:19 AM »
Yes, and you can do it with activex

Code: [Select]
(setq Outlk (vlax-Create-Object "CDO.Message"))

(setq Serv (vlax-Get-Property (vlax-Get-Property Outlk 'Configuration) 'Fields))
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/sendusing")      'Value 2)
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/smtpserver")     'Value "ServerSMTP") ; ex: smpt.aol.com
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/smtpserverport") 'Value 25)
(vlax-Invoke Serv 'Update)

(vlax-Put-Property Outlk 'From     "My_email@server.com")
(vlax-Put-Property Outlk 'To       "Recipient@server.com")
(vlax-Put-Property Outlk 'Subject  "Subject")
(vlax-Put-Property Outlk 'TextBody "My Message")
(vlax-invoke outlk 'AddAttachment  "My_Text.txt")

(if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke (list outlk 'Send)))
  (princ "\nImpossible to send the message. No connection Internet")
)

(vlax-Release-Object Outlk)

@+

Adesu

  • Guest
Re: Syntax for email
« Reply #5 on: January 23, 2007, 04:01:33 AM »
Hi Patrick,
I just tested your code,and got
Code: [Select]
#<VLA-OBJECT IMessage 08309104>
#<VLA-OBJECT Fields 07c34c5c>
nil
nil
nil
nil
nil
nil
nil
nil
; error: CDO.Message.1: The specified protocol is unknown.

_$

Yes, and you can do it with activex

Code: [Select]
(setq Outlk (vlax-Create-Object "CDO.Message"))

(setq Serv (vlax-Get-Property (vlax-Get-Property Outlk 'Configuration) 'Fields))
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/sendusing")      'Value 2)
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/smtpserver")     'Value "ServerSMTP") ; ex: smpt.aol.com
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/smtpserverport") 'Value 25)
(vlax-Invoke Serv 'Update)

(vlax-Put-Property Outlk 'From     "My_email@server.com")
(vlax-Put-Property Outlk 'To       "Recipient@server.com")
(vlax-Put-Property Outlk 'Subject  "Subject")
(vlax-Put-Property Outlk 'TextBody "My Message")
(vlax-invoke outlk 'AddAttachment  "My_Text.txt")

(if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke (list outlk 'Send)))
  (princ "\nImpossible to send the message. No connection Internet")
)

(vlax-Release-Object Outlk)

@+

Patrick_35

  • Guest
Re: Syntax for email
« Reply #6 on: January 23, 2007, 04:16:33 AM »
It's here. You must change the value of server SMPT by your SMTP
Code: [Select]
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/smtpserver")     'Value "ServerSMTP") ; ex: smpt.aol.com
But if the mail is already configured, this part of the code is not obligatory
Code: [Select]
(setq Serv (vlax-Get-Property (vlax-Get-Property Outlk 'Configuration) 'Fields))
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/sendusing")      'Value 2)
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/smtpserver")     'Value "ServerSMTP") ; ex: smpt.aol.com
(vlax-Put-Property (vlax-Get-Property Serv 'Item "http://schemas.microsoft.com/cdo/configuration/smtpserverport") 'Value 25)
(vlax-Invoke Serv 'Update)


@+

VVA

  • Newt
  • Posts: 166
Re: Syntax for email
« Reply #7 on: January 23, 2007, 04:57:04 AM »
Try It
Code: [Select]
;;Usage
;;;(send_message "Target@mail.ru" "Send DWG" "Hi, I send DWG-File.\nBye." "c:\\temp\\ABC.DWG")


(defun send_message (adr tema message Attachment / objOutlook MailItem AddAdresse objAttachment )
 
  (setq objOutlook (vlax-Create-Object "Outlook.Application"))
  (if objOutlook
    (progn
      (setq MailItem (vlax-Invoke-Method objOutlook 'CreateItem 0))
      (setq objMail (vlax-get-property Mailitem 'Recipients))
      (setq AddAdresse (vlax-Invoke-Method objMail 'Add adr))
      (setq objAttachment (vlax-get-property Mailitem 'Attachments))
      (vlax-Invoke-Method objAttachment 'Add Attachment 1 1 Attachment)
      (vlax-put-property Mailitem 'Subject tema)
      (vlax-put-property Mailitem 'Body message)
      (vlax-Invoke-Method MailItem 'Send)
    ); end progn
  ); end if

  (vlax-invoke-method objOutlook "Quit")
  (mapcar
    (function (lambda (x)
    (if
      (and x (not (vlax-object-released-p x)))
      (vlax-release-object x)
    );end if
  ))
    (list AddAdresse objAttachment objMail MailItem objOutlook)
  )
  (setq objOutlook nil MailItem nil objMail nil objAttachment nil AddAdresse nil)
  (gc)
  (princ)
); end defun


terrycadd

  • Guest
Re: Syntax for email
« Reply #8 on: January 23, 2007, 10:10:09 AM »
This is a very cool idea!  I tested the last posted function, without errors.  There is only one small issue I found on my system.  When I went to Outlook to check the status of the last sent message it reported "This message has not been sent."  So I pressed the [Send] button and then check my email and it went through.  Any ideas as to what else I need to modify on my system to make it initialize the Send property?


Adesu

  • Guest
Re: Syntax for email
« Reply #9 on: January 23, 2007, 08:46:10 PM »
Hi VVA,
Thanks for your sharing with my problem,here after I tested your code,your code still got trouble look at below
Code: [Select]
SEND_MESSAGE
_$

"adesu@telkom.net"
"Send DWG"
"Hi, I send DWG-File.\nBye."
"D:\\YBI\\Drawing\\Lat\\Gear.dwg"
; error: bad argument type: VLA-OBJECT nil
_$
Here your code I revised a few of part
Code: [Select]
(setq to "adesu@telkom.net")
(setq sub "Send DWG")
(setq bod "Hi, I send DWG-File.\nBye.")
(setq att "D:\\YBI\\Drawing\\Lat\\Gear.dwg")
(send_message to sub bod att)

Try It
Code: [Select]
;;Usage
;;;(send_message "Target@mail.ru" "Send DWG" "Hi, I send DWG-File.\nBye." "c:\\temp\\ABC.DWG")


(defun send_message (adr tema message Attachment / objOutlook MailItem AddAdresse objAttachment )
 
  (setq objOutlook (vlax-Create-Object "Outlook.Application"))
  (if objOutlook
    (progn
      (setq MailItem (vlax-Invoke-Method objOutlook 'CreateItem 0))
      (setq objMail (vlax-get-property Mailitem 'Recipients))
      (setq AddAdresse (vlax-Invoke-Method objMail 'Add adr))
      (setq objAttachment (vlax-get-property Mailitem 'Attachments))
      (vlax-Invoke-Method objAttachment 'Add Attachment 1 1 Attachment)
      (vlax-put-property Mailitem 'Subject tema)
      (vlax-put-property Mailitem 'Body message)
      (vlax-Invoke-Method MailItem 'Send)
    ); end progn
  ); end if

  (vlax-invoke-method objOutlook "Quit")
  (mapcar
    (function (lambda (x)
    (if
      (and x (not (vlax-object-released-p x)))
      (vlax-release-object x)
    );end if
  ))
    (list AddAdresse objAttachment objMail MailItem objOutlook)
  )
  (setq objOutlook nil MailItem nil objMail nil objAttachment nil AddAdresse nil)
  (gc)
  (princ)
); end defun


Adesu

  • Guest
Re: Syntax for email
« Reply #10 on: January 23, 2007, 08:52:41 PM »
Hi,
Why this code is nil
Code: [Select]
$ (setq objOutlook (vlax-Create-Object "Outlook.Application"))
nil
_$


Adesu

  • Guest
Re: Syntax for email
« Reply #11 on: January 23, 2007, 09:05:17 PM »
Hi Patrick_35,
Here code from and then I revised it as your suggest
Code: [Select]
(setq Outlk (vlax-Create-Object "CDO.Message"))
;(vlax-dump-object Outlk)
;(setq vgp (vlax-Get-Property Outlk 'Configuration))
;(vlax-dump-object vgp)
;(setq Serv (vlax-Get-Property vgp 'Fields))
;(vlax-dump-object Serv)
(setq Serv (vlax-Get-Property (vlax-Get-Property Outlk 'Configuration) 'Fields))
(setq http1 "http://schemas.microsoft.com/cdo/configuration/sendusing")
(setq http2 "http://schemas.microsoft.com/cdo/configuration/smtpserver")
(setq http3 "http://schemas.microsoft.com/cdo/configuration/smtpserverport")
(vlax-Put-Property (vlax-Get-Property Serv 'Item http1) 'Value 2)
(vlax-Put-Property (vlax-Get-Property Serv 'Item http2) 'Value "smtp.cbn.net.id")
(vlax-Put-Property (vlax-Get-Property Serv 'Item http3) 'Value 25)
(vlax-Invoke Serv 'Update)
(vlax-Put-Property Outlk 'From     "mteybid@yuasabattery.co.id")
(vlax-Put-Property Outlk 'To       "adesu_cad@yahoo.com.com")
(vlax-Put-Property Outlk 'Subject  "Test send email via autolisp")
(vlax-Put-Property Outlk 'TextBody "This email has been sended by autolisp program")
(vlax-invoke outlk 'AddAttachment  "Adesu.txt")
(if
  (vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke (list outlk 'Send)))
  (princ "\nImpossible to send the message. No connection Internet")
  )
(vlax-Release-Object Outlk)

Patrick_35

  • Guest
Re: Syntax for email
« Reply #12 on: January 24, 2007, 03:01:54 AM »
Hi
The advantage has my opinion to use (vlax-Create-Object “CDO.Message”) rather than (vlax-Create-Object “Outlook.Application”) it's that you don't need to have Outlook of installed on your PC.
You are useful yourself of Activex which is normally pass key Moreover
If you seek well, the shipper can be anonymous

@+

Adesu

  • Guest
Re: Syntax for email
« Reply #13 on: January 24, 2007, 08:56:15 PM »
Hi Patrick,
I hope you not bore to answer my question,your code in my opinion is "GOOD",but after I tested,it still got problem,at the recipient email not yet received,look at this below
Code: [Select]
Command: test

Enter Destination address <adesu_cad@yahoo.com>:

Enter subject for this email: test

Enter text body for this email: Test Hello

Command:
And here your code after I revised
Code: [Select]
(defun c:test (/ http1 http2 http3 outlk serv val val1 val2 val3
       vgp vgp_http1 vgp_http2 vgp_http3)
  (if
    (setq Outlk (vlax-Create-Object "CDO.Message"))
    (progn
      (setq vgp (vlax-Get-Property Outlk 'Configuration))
      (setq Serv (vlax-Get-Property vgp 'Fields))
      (setq http1 "http://schemas.microsoft.com/cdo/configuration/sendusing")
      (setq http2 "http://schemas.microsoft.com/cdo/configuration/smtpserver")
      (setq http3 "http://schemas.microsoft.com/cdo/configuration/smtpserverport")
      (setq vgp_http1 (vlax-Get-Property Serv 'Item http1))
      (setq val1 (vlax-get vgp_http1 'Value))
      (if
(/= val 2)
(vlax-Put-Property vgp_http1 'Value 2)
)                                      ; if
      (setq vgp_http2 (vlax-Get-Property Serv 'Item http2))
      (setq val2 (vlax-get vgp_http2 'Value))
      (if
(/= val2 "smtp.cbn.net.id")
(vlax-Put-Property vgp_http2 'Value "smtp.cbn.net.id")
)                                      ; if
      (setq vgp_http3 (vlax-Get-Property Serv 'Item http3))
      (setq val3 (vlax-get vgp_http3 'Value))
      (if
(/= val3 25)
(vlax-Put-Property vgp_http3 'Value 25)
)                                      ; if
      (vlax-Invoke Serv 'Update)
      (vlax-Put-Property Outlk 'From     "mteybid@yuasabattery.co.id")
      (setq desti (getstring t "\nEnter Destination address <adesu_cad@yahoo.com>: "))
      (if (= desti "")(setq desti "adesu_cad@yahoo.com"))
      (vlax-Put-Property Outlk 'To desti)
      (setq sub (getstring t "\nEnter subject for this email: "))
      (vlax-Put-Property Outlk 'Subject sub)
      (setq tb (getstring t "\nEnter text body for this email: "))
      (vlax-Put-Property Outlk 'TextBody tb)
      (vlax-invoke outlk 'AddAttachment  "D://YBI/Drawing/Lat/2 D/Gear.dwg")
      (if
(vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke (list outlk 'Send)))
(princ "\nImpossible to send the message. No connection Internet")
)
      (vlax-Release-Object Outlk)
      )                        ; progn
    (alert "\nit can not run this message")
    )                          ; if
  (princ)
  )                            ; defun

Adesu

  • Guest
Re: Syntax for email
« Reply #14 on: January 24, 2007, 08:58:49 PM »
Here data for that outlook
Code: [Select]
; before
_$

; IMessage: Defines methods, properties, and collections used to manage a message.
; Property values:
;   Attachments (RO) = #<VLA-OBJECT IBodyParts 04be45c8>
;   AutoGenerateTextBody = -1
;   BCC = ""
;   BodyPart (RO) = #<VLA-OBJECT IBodyPart 04be46f8>
;   CC = ""
;   Configuration = #<VLA-OBJECT IConfiguration 04be494c>
;   Configuration (RO) = ...Indexed contents not shown...
;   DataSource (RO) = #<VLA-OBJECT IDataSource 04be5060>
;   DSNOptions = 0
;   EnvelopeFields (RO) = CDO.Message.1: The requested property or feature, while supported, is not available at this time or in this context.

;   Fields (RO) = #<VLA-OBJECT Fields 07070ec4>
;   FollowUpTo = ""
;   From = ""
;   HTMLBody = ""
;   HTMLBodyPart (RO) = CDO.Message.1: The requested body part was not found in this message.

;   Keywords = ""
;   MDNRequested = 0
;   MimeFormatted = -1
;   Newsgroups = ""
;   Organization = ""
;   ReceivedTime (RO) = 0.0
;   ReplyTo = ""
;   Sender = ""
;   SentOn (RO) = 0.0
;   Subject = ""
;   TextBody = ""
;   TextBodyPart (RO) = CDO.Message.1: The requested body part was not found in this message.

;   To = ""

T
_$

; after
_$

; IMessage: Defines methods, properties, and collections used to manage a message.
; Property values:
;   Attachments (RO) = #<VLA-OBJECT IBodyParts 018528d0>
;   AutoGenerateTextBody = 0
;   BCC = ""
;   BodyPart (RO) = #<VLA-OBJECT IBodyPart 018508b0>
;   CC = ""
;   Configuration = #<VLA-OBJECT IConfiguration 01850984>
;   Configuration (RO) = ...Indexed contents not shown...
;   DataSource (RO) = #<VLA-OBJECT IDataSource 01850a58>
;   DSNOptions = 0
;   EnvelopeFields (RO) = CDO.Message.1: The requested property or feature, while supported, is not available at this time or in this context.

;   Fields (RO) = #<VLA-OBJECT Fields 07074ba4>
;   FollowUpTo = ""
;   From = "\"mteybid@yuasabattery.co.id\" <mteybid@yuasabattery.co.id>"
;   HTMLBody = ""
;   HTMLBodyPart (RO) = CDO.Message.1: The requested body part was not found in this message.

;   Keywords = ""
;   MDNRequested = 0
;   MimeFormatted = -1
;   Newsgroups = ""
;   Organization = ""
;   ReceivedTime (RO) = 0.0
;   ReplyTo = ""
;   Sender = ""
;   SentOn (RO) = 0.0
;   Subject = "Test send email via autolisp"
;   TextBody = "This email has been sended by autolisp program"
;   TextBodyPart (RO) = #<VLA-OBJECT IBodyPart 01852a20>
;   To = "\"adesu_cad@yahoo.com\" <adesu_cad@yahoo.com>"

T
_$