Hello,
I wrote a script that, among other things, sends an email with an attached binary file.
This goes through an SMTP relay server.
The problem is that the file gets corrupted along the way. something, somewhere, removes all 0x00 entries within the binary file.
I wonder if this could be due to the method I use to send the email.
Could someone have a look at this sub please ?
Sub SendMail (AttachmentFile)
Const SMTPServer = "zcabb37s.mydom.com"
Const SMTPServerPort = 25
Const MailExp = "myadd@mydom.com"
Dim Recipents, objMessage
Recipents = ""
For i = 0 To WScript.Arguments.Count - 1
If Len (Recipents) = 0 Then
Recipents = WScript.Arguments (i)
Else
Recipents = Recipents & "; " & WScript.Arguments (i)
End If
Next
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Stats du jour"
objMessage.From = MailExp
objMessage.To = Recipents
On Error Resume Next
objMessage.AddAttachment AttachmentFile
If Err.Number <> 0 Then
Call Echo ("Could not find attachment : " & " - " & Err.Number & Err.Source & " - " & Err.Description, 12)
Call Echo ("with " & AttachmentFile, 1)
WScript.Quit (5)
End If
On Error Goto 0
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPServerPort
objMessage.Configuration.Fields.Update
On Error Resume Next
objMessage.Send
If Err.Number <> 0 Then
Call Echo ("Could not send mail : " & " - " & Err.Number & Err.Source & " - " & Err.Description, 12)
Call Echo ("to " & Recipients, 1)
Call Echo ("with " & AttachmentFile, 1)
WScript.Quit (5)
End If
On Error Goto 0
Call Echo ("Mail sent to : " & Recipents & ".", 1)
Call Echo ("with attached file : " & AttachmentFile, 1)
End Sub