Send Email using VBScript
Post # 45 permalink Topic #45 by mreschke on 2008-04-29 10:13:54 (viewed 1,087 times)
Table of Contents

This is just a function snippet, sends an email with attachments, must manually edit function with email and attachment parameters.

Used in EmailLogs.vbs and ProcessManager.vbs

Script[-][- -][++]

VB Code Snippet
Sub SendLogEmail()
    Set pc = CreateObject("Wscript.Network")
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields
 
    Const schema = "http://schemas.microsoft.com/cdo/configuration/"
    dim emailBody
 
    Flds.Item(schema & "sendusing") = 2
    Flds.Item(schema & "smtpserver") = "xxx.xxx.xxx.xxx" 
    Flds.Item(schema & "smtpserverport") = 25
    Flds.Item(schema & "smtpauthenticate") = 0
    'Flds.Item(schema & "sendusername") = "domain\user"
    'Flds.Item(schema & "sendpassword") = ""
    Flds.Item(schema & "smtpusessl") = 0
    Flds.Update
 
    With iMsg
        .To = "you@mail.com,you2@mail.com"
        .From = "FromName <fromaddress@mail.com>"
 
        .Subject = pc.ComputerName & " log"
        .AddAttachment(logFile)
        .HTMLBody = "<b>SomeBody for email here, server: " & pc.ComputerName & "</b>"
 
        .Sender = "FromName <fromaddress@mail.com>"
        .Organization = "Your Company"
        .ReplyTo = "replyhere@mail.com"
 
        Set .Configuration = iConf
 
        .Send 
    End With   
 
    ' Release Interfaces
    Set iMsg = nothing
    Set iConf = nothing
    Set Flds = nothing
End Sub
 

Resources[-][- -][++]

http://www.paulsadowski.com/WSH/cdo.htm


Keywords

vbs vbscript visual basic script scripts email snippets ms microsoft studio .net shell scripting