• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VBS script to email via SMTP

Shmalls

Member
Hey everyone!

What I am trying to do is have people run this VBS which will pull down their username, computer name, computer SN, and take in a user defined variable (job number). It will then save this information to a file on the C: drive as "Computer Information.txt" with the format "username,computername,computerSN,job#". Then I want it to read in this file to the variable BodyText which I can then place in the body of the email. Every time I do this I get some computer code in the body and not what I want.

Does anyone have a suggestion on making this work, I want those variable to show up in the body, I dont care how we do it.


Thanks!!!!




----BEGIN CODE--------------------------------------

Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "localhost")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
Set WshNetwork = WScript.CreateObject("WScript.Network")

on error resume next
Strjnum=InputBox ("What is the Job Number for the site you are at? (xx-xxx)")
Set objWMIService = GetObject(Strjnum)


For each objitem in colitems

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

'---These constants are defined to make the code more readable

Dim fso, info
Set fso = CreateObject("Scripting.FileSystemObject")
Set info = fso.CreateTextFile("C:\Computer Information.txt", 8, True)
info.write WshNetwork.UserName
info.write (",")
info.write WshNetwork.ComputerName
info.write (",")
info.write objitem.serialnumber
info.write (",")
info.write Strjnum
info.Close
next
Dim CI
'---Open the file for reading
Set CI = fs😵penTextFile("C:\Computer Information.txt", ForReading)

'---The ReadAll method reads the entire file into the variable BodyText
BodyText= CI.ReadAll
'---Close the file
CI.Close
Set CI = Nothing
Set fso = Nothing






Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "TEST TEST TEST"
objMessage.From = """PC Inventory Project"" <ithelp@******.com>"
objMessage.To = "dkuhry@******.com"
objMessage.TextBody = BodyText


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

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

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...nfiguration/smtpserver") = "**********.com"

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

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...iguration/sendusername") = "ithelp@******.com"

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

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

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...nfiguration/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/c.../smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

wscript.echo "Thank you"



--------END CODE---------------
 
Got it, I cut out a lot of the fat and figured out how to do it without creating the txt file

Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "localhost")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
Set WshNetwork = WScript.CreateObject("WScript.Network")

on error resume next
Strjnum=InputBox ("What is the Job Number for the site you are at? (xx-xxx)")
Set objWMIService = GetObject(Strjnum)

For each objitem in colitems

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 = "Computer Information"
objMessage.From = """PC Inventory Project"" <ithelp@******.com>"
objMessage.To = "ithelp@******.com"
objMessage.TextBody = WshNetwork.UserName & (",") & WshNetwork.ComputerName & (",") & objitem.serialnumber & (",") & Strjnum


+ smtp code
 
Back
Top