I am sorry guys it turns out my code was fine all along, they had security issues socket closed. As the code just ended I was unable to pinpoint the error. I only found this out when sending through BMail. Thanks for your help. Below is the steps from VB (SMTP), Bmail (creates a batch file and runs) and groupwise automation for anyone who needs it.
Standard VB
Dim iMsg
Dim iConf
Dim Flds
Const cdoSendUsingPort = 2
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
With Flds
.Item("
= cdoSendUsingPort
.Item("
= SMTPServerName
.Item("
= 10
.Update
End With
With iMsg
Set .Configuration = iConf
.To = GetEmailAddress(rstMailDetails.Fields(0))
.From = EmailSentFrom
.Subject = EmailSubject
.HTMLBody = EmailBody
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
Alternatively BMail (free exe program – bmail.exe, creates a batch file and runs)
Private Sub SendBMail(LocOfBMail, ToEmail, FromEmail, smtpserver, EmailSub, EmailBody, PortNo)
On Error GoTo Error_Handler
Dim RunExe, StringToShell
StringToShell = LocOfBMail & "bmail -h -t " & ToEmail & " -f " & FromEmail & " -s " & smtpserver & " -a " & EmailSub & " -b " & EmailBody & " -p " & PortNo
Dim TempFile As String
TempFile = CurrentProject.Path & "\a.bat"
Dim iFileNo As Integer
iFileNo = FreeFile
Open TempFile For Output As #iFileNo
Print #iFileNo, StringToShell
Close #iFileNo
RunExe = Shell(TempFile, vbHide)
Exit Sub
Error_Handler:
MsgBox "error occured when sending the BMail! -" & Err.Number & vbCrLf & Err.Description
End Sub
Or Else groupwise automation (download free program - gwsend.exe)
Private Sub SendGWMail(GWEXELoc, EmailAdd)
On Error GoTo EH
Dim wshell
wshell = Shell(GWEXELoc & " /t=" & EmailAdd & " /s=""Email Subject"" /m=""Email body""", vbHide)
Set wshell = Nothing
Exit Sub
EH:
MsgBox "Error occured number : - " & Err.Number & vbCrLf & Err.Description
End Sub