**DONOTDELETE**
(Lurker)
2002-09-16 09:10 PM
Send E-mail with COM

I read Shawn's script on sending an e-mail with OLE and was really impressed. (But then again Shawn is the king of OLE as I have learned from the past posts) but what about COM. Can it be done?

By the way, is it impossible to send an e-mail with Service pack 2 in place? I got the impression that it is impossible. Radimus posted a solution (I think). It was to register Kixtart. We are service packed to the hilt here and so any e-mailing would have to get past the patches. As far as a third party solution for e-mailing is concerned, I'd like to avoid it. They are as cheap as a $2 whore here (excuse the euphemism) and I doubt they would spring for said solutions. Any thoughts on this?

Kirk [Confused]

P.S. Sorry to post here but I tried to post on the original thread and it wouldn't work. I think it may be closed although nothing appeared to indicate this.


Radimus
(KiX Supporter)
2002-09-16 09:34 PM
Re: Send E-mail with COM

to COM, you have to COM something. The problem is that SP2 kills the automated COM mail routines... unless someone has hacked their way around it.

Many use BLAT, and there was even a post using telnet to post directly to smtp port.

I have a the script log events that would have been mailed to me, and a admin app for me that parses, looking for new events...

your solution is kind of specific as to what you would like to do.


Sealeopard
(KiX Master)
2002-09-16 10:26 PM
Re: Send E-mail with COM

You could always use Lonkero's TELNET solution. Unless, of course the TELNET interface to the SMTP mail server has been disabled.

LonkeroAdministrator
(KiX Master Guru)
2002-09-16 10:37 PM
Re: Send E-mail with COM

actually, the telnet solution has nothing to do with telnet interface.

the solution using telnet, is behaving like smtp server.

like, you can send mail in your own network as your boss to everyone if your net has not disabled internal smtp.


Sealeopard
(KiX Master)
2002-09-16 11:17 PM
Re: Send E-mail with COM

Lonkero: I did mean the TELNET interface into an SMTP service. Your solution uses TELNET to send certain strings to port 25 of an SMTP Server in order to send an email. However, some email servers have the ability to deny this type of connection while still allowing regular email clients to send email via SMTP.

LonkeroAdministrator
(KiX Master Guru)
2002-09-16 11:21 PM
Re: Send E-mail with COM

well, only ability is disable usage of plain text connections.
this means, that even the normal clients using pop3 and such would need to use ssl or similar.

this type of disabling I have not seen used pretty much as normal servers using internet mail connector do not handle mail coming from clients but other smpt servers.


ShawnAdministrator
(KiX Supporter)
2002-09-16 11:33 PM
Re: Send E-mail with COM

Kirk ... hows it going bud ? i think your best bet is to track-down that "registering kixtart" thingy you mentioned earlier .. see if you can find any more info on that ... the port from old OLE to the new COM is very straight-forward. But no good unless you can get past that security patch they put in.

[ 16. September 2002, 23:34: Message edited by: Shawn ]


**DONOTDELETE**
(Lurker)
2002-09-16 11:41 PM
Re: Send E-mail with COM

[Embarrassed]

Sorry Guys, I should have been more specific. I use Kixtart (Version 4.11) to run back ups on our network. We have Win9x and 2k boxes. I am sending the results of the backups to a text file (Log) but I want the script to be able to e-mail me if a backup Errors. That way I can make sure the universe is unfolding as it should (To quote a former Prime Minister of our large and somewhat cold country.) The Telnet solution sounds somewhat intriguing but the thing is that our e-mail is supplied by a local ISP. We don't have Exchange or any other sort of internal e-mail. By the way, the network is P2P. Yeah, I know, but like I said they are extremely cheap here.

Kirm


**DONOTDELETE**
(Lurker)
2002-09-16 11:47 PM
Re: Send E-mail with COM

Hi Shawn

Good to hear from you again.

So if I understand the situation correctly, If I register Kixtart with Radimus' solution then Windows will let Kixtart e-mail me. I'm going to try it and I'll post the results. This could take a while but I shall return.

Kirm


**DONOTDELETE**
(Lurker)
2002-09-17 12:12 AM
Re: Send E-mail with COM

Back again

Used radimus' script to register Kixtart...with some changes for my editor
code:
$kix="HKEY_CLASSES_ROOT\.KIX"
$kixautofile="HKEY_CLASSES_ROOT\KIX_auto_file"
AddKey("$kix")
WriteValue("$kix","","KIX_auto_file",REG_SZ)
AddKey("$kixautofile")
WriteValue("$kixautofile","","KiXtart Script",REG_SZ)
WriteValue("$kixautofile","EditFlags","0",REG_SZ)
AddKey("$kixautofile\DefaultIcon")
WriteValue("$kixautofile\DefaultIcon","","%windir%\system32\SHELL32.dll,21",REG_EXPAND_SZ)
AddKey("$kixautofile\shell")
WriteValue("$kixautofile\shell","","Run",REG_SZ)
AddKey("$kixautofile\shell\Edit")
AddKey("$kixautofile\shell\Edit\command")
WriteValue("$kixautofile\shell\Edit\command","","C:\Program Files\RWK Systems\KiXscripts Editor\KiXscriptEditor.exe %1",REG_EXPAND_SZ)
AddKey("$kixautofile\shell\Run")
AddKey("$kixautofile\shell\Run\command")
WriteValue("$kixautofile\shell\Run\command","","%windir%\kix32.exe %1",REG_EXPAND_SZ)

This should be OK, right? I made allowances for my Kixtart editor.

Now running Shawn's OLE e-mail.
code:
Break on 
CLS
$recipient = "kirk@@volvotruckcentre.com" ; use double @@'s
$subject = "This is the subject"
$message = "This is the message body"
$outlook = OLECreateObject("outlook.application")
$namespace = Val("&" + OLECallFunc($outlook, "getnamespace", "s", "MAPI"))
$= OLECallFunc($namespace, "logon")
$mailitem = Val("&" + OLECallFunc($outlook, "createitem", "s", "0"))
$recipients = Val("&" + OLEGetProperty($mailitem, "recipients"))
$ = OLECallFunc($recipients, "add", "s", "$recipient")
$ = OLEPutProperty($mailitem, "subject", "s", "$subject")
$ = OLEPutProperty($mailitem, "body", "s", "$message")
$ = OLECallFunc($mailitem, "send")
$ = OLECallFunc($namespace, "logoff" )
$ = OLEReleaseObject($recipients)
$ = OLEReleaseObject($mailitem)
$ = OLEReleaseObject($outlook)
Exit

The Code errors on this line:
code:
$namespace = Val("&" + OLECallFunc($outlook, "getnamespace", "s", "MAPI"))

It's strange because running throught the debugger it displays this line:

$outlook = OLECreateObject("outlook.application")

and then repeats this part:

("outlook.application")

It's almost like it doesn't recognize the OLE reference. This may be a matter of it not allowing Outlook to be used by Kixtart in spite of the registration.

Kirk

P.S. I'm doing it in OLE first to see if I can get it working and then I'll translate it into COM.


LonkeroAdministrator
(KiX Master Guru)
2002-09-17 12:29 AM
Re: Send E-mail with COM

damn... nameservers crashing all the time! [Mad]

anyway, if you check from the manual the createobject, you see that there is no such thing anymore as olecreate...

it has been replaced with the createobject which supports com.
so, changing your ole-calls to com calls should do the job.


**DONOTDELETE**
(Lurker)
2002-09-17 12:44 AM
Re: Send E-mail with COM

You can say that again Lonkero. OLE isn't available anymore in Kixtart 4.11. So I COMed it. I read Shawns primer on COM (Should have done this from the beginning) Anyway this works without an error:
code:
Break on 

$recipient = "kirk@@volvotruckcentre.com" ; use double @@'s
$subject = "This is the subject"
$message = "This is the message body"
$outlook = CreateObject("outlook.application")
?"Outlook = " + $outlook
$outlook.visible=1
If @ERROR <> 0
?"Error"
Else
?"Outlook is running"
EndIf

It outputs
Outlook = Outlook
Outlook is running

Strange huh?

The problem is that Outlook isn't running. It doesn't show up in task manager, anyway. I suspect I'm running up against Outlook security.

Any thoughts?


LonkeroAdministrator
(KiX Master Guru)
2002-09-17 12:49 AM
Re: Send E-mail with COM

well, I quess it's all about the default object property.

mmm, there was some 2-3 days ago really simple outlook script out in these forums...


Breaker
(Hey THIS is FUN)
2002-09-17 11:09 AM
Re: Send E-mail with COM

What version of Outlook are you trying to use? If it's 98+ with the Outlook security patch applied, then programmatic access to Outlook is disabled. There's a lot of stuff on MSDN about how to get around this, but unless you have an Exchange environment and a helpful Exchange admin, you are still going to have Outlook asking you whether to allow access to email every time your script (or any other application) runs.

I'll dig out a couple of links and post them here later today, but basically the fix was to create a new public folder in the Exchange organisation, download a custom form from M$, make a couple of reg hacks on the machines that would run the script, or application, or whatever, and then Robert's your father's brother. Trouble is, you'll need a lot of rights on your Exchange box and your client machines to do it.

Back later with links...


LonkeroAdministrator
(KiX Master Guru)
2002-09-17 11:33 AM
Re: Send E-mail with COM

kirm,

have you tried that your isp server...

telnet to it's port 25

if it gives you a connection, it might ask for helo-ehlo, but after that write the rcpt to and mail from things with your own internal address and see if it lets the mail come true.

if there is good security, it does not let it, but try.
I don't remember the correct keywords, but they are there in my smtp-mail udf.

if it accepts the addresses post some crap.


**DONOTDELETE**
(Lurker)
2002-09-17 04:15 PM
Re: Send E-mail with COM

To reply to everyone who posted: We don't have internal e-mail. No exchange server. Our E-mail provider cannot be telneted to and we are using Outlook 2000 or 2002 with all the latest security patches. Why does Outlook have to be used to send an e-mail? There has to be another way and I'll find it. The tough part is is has to be free.

Kirm

P.S. I'm not really sure of my Telneting ability. If some one could confirm I would appreciate it. I open up a prompt and type telnet. Then I type:

open pop.interbaun.com:25

This comes back saying it couldn't open a connection to the host.


Radimus
(KiX Supporter)
2002-09-17 04:35 PM
Re: Send E-mail with COM

What you need to realize is that the security patches for outlook were designed to specifically prevent what you want to do...

you can still COM it, but Outlook will pop up warning messages on the desktop asking "do you want to do this??"

telnet to your smtp mailserver, not the pop server


**DONOTDELETE**
(Lurker)
2002-09-17 10:36 PM
Re: Send E-mail with COM

Hello everyone

I've found out a bunch of stuff so I though I'd share. (It's nothing that anybody doesn't already know) Radimus is correct about the security patches. What I'd like to know is how do all these low quality virii, which seem to come out every week, use outlook's address book to send themselves to other people. Hell, that Klez virus could not only send itself to people but it would spoof the senders address.

SMTP does work with our ISP. I was just doing it incorrectly. I found that out through Lonkero's telnet script. The only part of his script that wouldn't work after a few mods was that the from address had to be a valid e-mail and the body wasn't sent. I'm sure these are peculiarities with our mail server and not Lonkero's UDF. Then again, I believe that the subject and body must be wrapped in qoutes. If I sent a single word subject it worked but multiple words and nothing was seen in the subject line after the e-mail arrived. Kudos to Lonkero for his masterful scripting and all round knowledgableness of the SMTP world.

Here is the modified code I used(and it did work...at least partly):

code:
SendMail("199.185.130.23","kirk@@volvotruckcentre.com","kirk@@volvotruckcentre.com","test","I am just testing... nothing more nothing less")
Function SendMail($server,$from,$to,$subject,$message)
If (2>Len($server) OR 2>Len($from) OR 2>Len($to) OR 2>Len($subject) OR 2>Len($message))
Exit(13)
EndIf
Run '%comspec% /c start "SendMail ' + $server + '" /MIN telnet $server 25'
Sleep 15
If SetFocus ("SendMail " + $server) <> 0
Exit(53)
EndIf
Sleep 2
If SetFocus ("SendMail "+$server) <> 0
Exit(53)
EndIf
$r = ""+ SendKeys("MAIL FROM:$from{ENTER}")
Sleep 1
$r = $r +","+ SendKeys("RCPT TO:$to{ENTER}")
Sleep 1
$r = $r +","+ SendKeys("DATA{ENTER}")
Sleep 1
$r = $r +","+ SendKeys("Subject: $subject{ENTER}")
Sleep 1
$r = $r +","+ SendKeys("$message{ENTER}")
$r = $r +","+ SendKeys(".{ENTER}")
Sleep 1
$r = $r +","+ SendKeys("QUIT{ENTER}")
$SendMail = $r
Exit(0)
EndFunction

Once again this is Lonkero's code. I have just modified it slightly.

I have found a work around for my problem too. I just downloaded Blat and read the license agreement and it appears to be freeware. I tinkered with it and was amazed at how well it worked. So that is the route I will take. I'm just not so sure it will work with 9x

Thank you everyone for your help.


LonkeroAdministrator
(KiX Master Guru)
2002-09-17 10:39 PM
Re: Send E-mail with COM

did you get your message to show?

it should need one empty line after the subject...


**DONOTDELETE**
(Lurker)
2002-09-17 10:57 PM
Re: Send E-mail with COM

Yep I got it to work and you were right Lonkero it needed another space. Here's the line I changed:

$r = $r +","+ SendKeys("Subject: $subject{ENTER}{ENTER}")

I just entered another {ENTER}. It works great now Except it still doesn't show anything in the "to" and "from" boxes. Actually in the "to" box it says: undisclosed-recipients:

Very interesting! This could be the next great spamming tool. Just what the world needs [Razz]


LonkeroAdministrator
(KiX Master Guru)
2002-09-17 11:03 PM
Re: Send E-mail with COM

like I said before, with it you can mail as your boss, neat isn't it? [Big Grin]

**DONOTDELETE**
(Lurker)
2002-09-18 12:48 AM
Re: Send E-mail with COM

Yeah, it's pretty cool but how do you mean you could mail as your boss? I can't get the Sender's and recipient's addresses to show up on the sent e-mails. It goes to where it's supposed to and the Subject line and message body are there but the "from" and "to" fields are blank.

LonkeroAdministrator
(KiX Master Guru)
2002-09-18 12:57 AM
Re: Send E-mail with COM

well, I did test drive on our network and then disabled that totally [Big Grin]

if you do:
mail from:your_boss_e-mail@your.domain
rcpt to:bill.gates@microsoft.com

it should go just fine.
I don't know why the addresses do not show up as they should.
might be that your isp's e-mail server is stupid that it can't use the real e-mail address as displayname....
dunno.


Breaker
(Hey THIS is FUN)
2002-09-18 11:12 AM
Re: Send E-mail with COM

Just as an update to the intertwined discussion here about the limitations of the Outlook security update - here is the article I used to help me get around this for an Access application I wrote earlier this year.

Q263297 - Admin Info about the Outlook E-mail Security Update

There's a couple of links in the article telling you where to download the admin tools and how to set up the admin custom form for email security settings - v. useful if you have Exchange and have problems sending mail programmatically by automating Outlook in your scripts.

Obviously there are other ways (Blat, Postie, direct telnet session to SMTP, etc) but sometimes its nice to leverage the framework that's already in place, using the otions to keep copies of sent mail, etc.

By the way, Lonkero - is there anywhere you can point me to for an SMTP command reference? Thanks in advance!


LonkeroAdministrator
(KiX Master Guru)
2002-09-18 11:20 AM
Re: Send E-mail with COM

well, here is easy to read one...
and links:
http://www.networksorcery.com/enp/protocol/smtp.htm


**DONOTDELETE**
(Lurker)
2002-09-18 04:32 PM
Re: Send E-mail with COM

Read your Reference Lonkero and found this interesting tidbit in the Memo that the commands refer to:

The second step in the procedure is the RCPT command.

RCPT TO:"<"forward-path">" [ SP "<"rcpt-parameters">" ]

The first or only argument to this command includes a forward-path
(normally a mailbox and domain, always surrounded by "<" and ">" brackets) identifying one recipient.

Could this be the reason I can't see the "to" and "from" fields? I'll give it a try and get back to you.

Kirm

P.S. I had to put qoutes on the command brackets or they are striped.


Richard H.Administrator
(KiX Supporter)
2002-09-18 05:09 PM
Re: Send E-mail with COM

You will need to use message headers to add the information.

Immediately after the "DATA" and before you enter the blank line, issue the fields:
code:
From: Display_From_Name <from@address>
To: Display_To_Name <to@address>
Subject: Subject_Line

Your blank line seperated the mail headers from the actual message.

There are loads of headers for return receipts, MIME encoding and so-on.


**DONOTDELETE**
(Lurker)
2002-09-18 05:29 PM
Re: Send E-mail with COM

Thanks Richard. That's done it...at least partially.

Here's my code:

code:
 $r = $r +","+ SendKeys("DATA{ENTER}") 
Sleep 1
$r = $r +","+ SendKeys("From: Kirk <kirk@volvotruckcentre.com>{ENTER}")
Sleep 1
$r = $r +","+ SendKeys("To: Captain Kirk <kirk@volvotruckcentre.com>{ENTER}")
Sleep 1
$r = $r +","+ SendKeys("Subject: $subject{ENTER}{ENTER}")
Sleep 1

And here's what comes out:

From: Kirk [kirk unknown:volvotruckcentre.com]
To: Captain Kirk

It's definately picking up the aliases but is missing the actual addresses. Must be our mail server.


Richard H.Administrator
(KiX Supporter)
2002-09-18 05:43 PM
Re: Send E-mail with COM

Don't forget to double up those "@" signs to avoid conflicts with macros..
"Kirk@@volvotruckcentre.com", not "Kirk@volvotruckcentre.com"


LonkeroAdministrator
(KiX Master Guru)
2002-09-19 08:44 AM
Re: Send E-mail with COM

I quess one has to update his udf...
and did.

[ 19. September 2002, 09:19: Message edited by: Lonkero ]