I have a process that loops through records and sends an email for each one it finds. I did not write this but use it to send email through the Exchange server, not personal email account. You will need to talk to your email admin on the schemas info.
Call the function:
Sendit = Send_Mail(rs1!AddressEmail, "", "script@aaa.com", "Subject", "Body")
Public Function Send_Mail(ByVal MailTo As String, ByVal Mailcc As String, ByVal MailFrom As String, ByVal MailSubject As String, MailBody As Variant)
On Error GoTo ErrTrap
Dim LoopFlag As Boolean
Dim Pos As Integer
Dim TempString As String
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "xx.x.x.xx" exchange server IP
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxx"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxx"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
Do While LoopFlag = False
DoEvents
' Get next recipient from MAILTO List
Pos = InStr(1, MailTo, ";")
If Pos = 0 Then
LoopFlag = True
TempString = MailTo
Else
TempString = Left(MailTo, (Pos - 1))
MailTo = Right$(MailTo, (Len(MailTo) - Pos))
End If
TempString = Trim(TempString)
MailTo = Trim(MailTo)
With iMsg
Set .Configuration = iConf
.To = TempString
.CC = Mailcc
.From = MailFrom
.Subject = MailSubject
.TextBody = MailBody
' If FileName <> "" Then
' .AddAttachment FileName
' End If
.Send
End With
Loop
Set iMsg = Nothing
Set iConf = Nothing
Exit Function
ErrTrap:
' If a crash is necessary (specified by setting the HaltOnError flag)
' script will stop with a popup message, if message is informational,
' the script will resume without sending the message
' If HaltOnError Then
MsgBox "Email Error" + vbCrLf + MessageNoteSubject + vbCrLf + "to Recipient: " + TempString + vbCrLf + "Error: " + Err.DESCRIPTION, vbCritical + vbOKOnly, "Error (" + CStr(Err.Number) + ")"
Close
End
' Else
' Resume Next
' End If
End Function