Public Sub GetData2Mail()
Dim rst As DAO.Recordset
Dim strBody
Dim Sendto1, Esubject
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("L:\teste.txt", ForReading)
strBody = f.ReadAll
f.Close
Set rst = Form_RC_S_NC.RecordsetClone
'send 1 email with everyones address, or
'sent many emails, 1 per person
While Not rst.EOF
Sendto1 = rst!
Esubject = "Teste" & " " & rst![SAP] & " " & rst![Nome]
SendEmail Sendto1, Esubject, strBody
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
End Sub
Private Sub SendEmail(ByVal pvTo, ByVal pvSubj, ByVal pvBody)
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'Dim strBody2
Dim Session As Object
Dim EmbedObj1 As Object
On Error GoTo errorhandler1
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GetDatabase("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
Recipient = Sendto1
With MailDoc
.SendTo = pvTo
.Subject = pvSubj
.Body = pvBody
.PostedDate = Now()
End With
MailDoc.Send 0, Sendto1
MailDoc.Save = True
endit:
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing
Exit Sub
errorhandler1:
MsgBox Err.Description, , Err
Resume endit
End Sub
[/code]
Monday, September 22, 2014 4:42:51 PM |
valcompv@hotmail.com; ghostline40 |
Public Sub GetData2Mail()
Dim rst As DAO.Recordset
Dim strBody
Dim Sendto1, Esubject
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("L:\teste.txt", ForReading)
strBody = f.ReadAll
f.Close
Set rst = Form_RC_S_NC.RecordsetClone
'send 1 email with everyones address, or
'sent many emails, 1 per person
While Not rst.EOF
Sendto1 = rst!
Esubject = "Teste" & " " & rst![SAP] & " " & rst![Nome]
SendEmail Sendto1, Esubject, strBody
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
End Sub
Private Sub SendEmail(ByVal pvTo, ByVal pvSubj, ByVal pvBody)
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'Dim strBody2
Dim Session As Object
Dim EmbedObj1 As Object
On Error GoTo errorhandler1
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GetDatabase("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
Recipient = Sendto1
With MailDoc
.SendTo = pvTo
.Subject = pvSubj
.Body = pvBody
.PostedDate = Now()
End With
MailDoc.Send 0, Sendto1
MailDoc.Save = True
endit:
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing
Exit Sub
errorhandler1:
MsgBox Err.Description, , Err
Resume endit
End Sub
[/code][/QUOTE]
While Not rst.EOF
Sendto1 = Sendto1 & rst! & ";"
rst.MoveNext
Wend
Esubject = "Teste" & " " & rst![SAP] & " " & rst![Nome]
SendEmail Sendto1, Esubject, strBody
rst.Close
Set rst = Nothing
End Sub
[/code][
Here's the loop for 1 email to many.
yes paste in the button click
Rich (BB code):While Not rst.EOF Sendto1 = Sendto1 & rst! & ";" rst.MoveNext Wend Esubject = "Teste" & " " & rst![SAP] & " " & rst![Nome] SendEmail Sendto1, Esubject, strBody rst.Close Set rst = Nothing End Sub [/code][[/QUOTE]