so as of right now my code is
i was wondering if there was a way to do
and was also wondering if I could include what line caused the error in the log file
Code:
Option Explicit
On Error resume next
dim attachment
dim subject
attachment = WScript.Arguments.Item(0)
'msgbox attachment,vbInformation
subject = WScript.Arguments.Item(1)
'msgbox subject, vbInformation
'MSGBOX "BREAK"
Dim objshell, objfso, emailobj, FSO_Handle, emailConfig
Dim strDate, strTime, strDateTime, strPath, strName
Set objShell = CreateObject("WScript.Shell")
Set objFSO = WScript.CreateObject("Scripting.Filesystemobject")
Set emailObj = CreateObject("CDO.Message")
strPath = objShell.ExpandEnvironmentStrings("%TEMP%")
strDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
strTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
strName = strPath & "\emaillog.txt"
strDateTime = strDate & "-" & strTime
emailObj.From = "from"
emailObj.To = "to"
emailObj.Subject = Subject
emailObj.TextBody = SUBJECT
emailObj.AddAttachment attachment
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
emailConfig.Fields.Update
emailObj.Send
'Err.Raise 6 'To test if the error is getting stored or not
If err.number = 0 then Msgbox "EMAIL SENT"
Set FSO_Handle = objFSO.OpenTextFile (strname,8,True)
If Err.Number <> 0 Then
FSO_Handle.WriteLine Now & strdatetime & " - Error : " & Err.Number & ": " & Err.Description & ": " & err.source
msgbox (strdatetime & " - Error : " & Err.Number & ": " & Err.Description & ": " & err.source)
End IfCode:
Option Explicit
Dim objshell, objfso, emailobj, FSO_Handle, emailConfig, objwrite
Dim strDate, strTime, strDateTime, strPath, strName, attachment, subject
Set objShell = CreateObject("WScript.Shell")
Set objFSO = WScript.CreateObject("Scripting.Filesystemobject")
Set emailObj = CreateObject("CDO.Message")
strPath = objShell.ExpandEnvironmentStrings("%TEMP%")
strDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
strTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
strName = strPath & "\emaillog.txt"
strDateTime = strDate & "-" & strTime
objwrite = FSO_Handle.WriteLine Now & strdatetime & " - Error : " & Err.Number & ": " & Err.Description & ": " & err.source
On Error objwrite