Link to home
Start Free TrialLog in
Avatar of gateguard
gateguard

asked on

vbscript to send smtp mail

How do I script the following commands, instead of having to type them one-by-one in command line?

If I type these commands in command line, the mail is sent:

telnet mail.test.com 25
EHLO test.com
MAIL FROM:Admin@test.com
RCPT TO: User@test.Com
DATA
Subject: test message
text
text

.
QUIT


(mail.test.com is a mail server on my LAN)
SOLUTION
Avatar of Mortaza Doulaty
Mortaza Doulaty
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gateguard
gateguard

ASKER

I get this error:

C:\sendmail.vbs(4, 1) Microsoft VBScript runtime error: Class not defined: 'vbSendMail'
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> I get this error:
>>C:\sendmail.vbs(4, 1) Microsoft VBScript runtime error: Class not defined: 'vbSendMail'

Maybe you have not registered the vbsendmail.dll, try registering that dll file,
run this from the command:

regsvr32 vbsendmail.dll
Mortaza, the way that the sendmail code is written in the link you provided, it looks like strict VB6, and would not be compatible with VBScript because of the type declarations.  Gateguard, if you have VB6, run this code in that.

Otherwise, my vbs script should run (as long as you have blat.exe) on Windows 2000 or later.

Regards,

Rob.
>>Mortaza, the way that the sendmail code is written in the link you provided, it looks like strict VB6, and >>would not be compatible with VBScript because of the type declarations.

Yes, that code is strict VB6

I thought that could help...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I went with the Outlook solution since I do have Outlook installed on all the machines I'm running this script on.  But thanks for the other ideas also.  I might use them in other cases.
Rob,  I am going to test blat and I will let you know.  I'll put a comment in here.
If you want to use VBScript here is a script that works using CDO:


Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Test Message"
objMessage.Sender = "user@domain.com"
objMessage.From = "user@domain.com"
objMessage.To = "recipient@domain.com"
objMessage.TextBody = "Test"

'==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous

'Your UserID on the SMTP server
'objMessage.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user@domain.com"

'Your password on the SMTP server
'objMessage.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update
objMessage.Send

If Err.number <> 0 then
      response.write Err.number & " " & Err.Description & "<BR>"
End If