나는 자동으로 전자 메일을 보내려는 MS Access 2010 db가 있습니다. 쿼리를 설정했지만 CDO VBA에 문제가 있습니다. 그들은 'qryEmails'라고하며 다음의 4 개 가지 필드가 포함되어 있습니다 쿼리 내가 액세스 어떻게합니까CDO 전자 메일 자동화
ReturnCode, SalesOrderNumber, Name, EmailAddress
: 나열된 각 레코드를 통해
- 루프를 각각의 이메일 주소로 이메일을 보내을
- 각 이메일에 처음 세 입력란에 대한 참조가 포함될 메시지가 있으므로 각 메시지가 맞춤 설정되어 나타납니다.
- 동적 제목이 있으므로
ReturnCode
필드가 각 제목에 있습니다.
나는 처음에는 작은 단계를 시도해 왔지만 지금까지 동일한 주소로 100 개의 이메일을 받았습니다. 여기에 내 코드가 있습니다 (나는 정보를 공개하고 싶지 않은 XXX를 사용했습니다) :
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim strEmail As String
Set rst = New ADODB.Recordset
'
strSQL = "[qryEmails]" 'source of recordset
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
'
Do While Not rst.EOF
strEmail = rst.Fields("EmailAddress")
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Your refund is:" '
objMessage.FROM = """SENDER"" <[email protected]>"
objMessage.To = rst.Fields("EmailAddress")
objMessage.TextBody = objMessage.TextBody & rst(1)
'==Add fields to email body
'Do While strEmail = rst.Fields("EmailAddress")
'rst.MoveNext
'If rst.EOF Then Exit Do
'Loop
' ========= SMTP server configuration
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "XXX"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
'Send email
objMessage.Send
'Clear variable for next loop
Set objMessage = Nothing
Loop
rst.Close
Set rst = Nothing
왜 이것이 100 개의 이메일을 보내고 있는지 알고 싶습니다. 지금까지 쿼리 결과는 테스트 목적으로 두 개의 주소 만 반환합니다.