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)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> 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
>>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.
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...
Yes, that code is strict VB6
I thought that could help...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
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.F ields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.F ields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.F ields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous
'Your UserID on the SMTP server
'objMessage.Configuration. Fields.Ite m _
'("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user@domain.com"
'Your password on the SMTP server
'objMessage.Configuration. Fields.Ite m _
'("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
'Server port (typically 25)
objMessage.Configuration.F ields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.F ields.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.F ields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.F ields.Upda te
objMessage.Send
If Err.number <> 0 then
response.write Err.number & " " & Err.Description & "<BR>"
End If
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.F
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.F
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.F
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous
'Your UserID on the SMTP server
'objMessage.Configuration.
'("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user@domain.com"
'Your password on the SMTP server
'objMessage.Configuration.
'("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
'Server port (typically 25)
objMessage.Configuration.F
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.F
("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.F
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.F
objMessage.Send
If Err.number <> 0 then
response.write Err.number & " " & Err.Description & "<BR>"
End If
ASKER
C:\sendmail.vbs(4, 1) Microsoft VBScript runtime error: Class not defined: 'vbSendMail'