This is a copy of a code snippet from a program I wrote a long time ago.
It reads a file to get the names of who to send the message to, then sends a text file to the person(s) in the list
to make it work
Sub Command1_click()
MailIt
End Sub
Sub mailIt()
Dim msgtext As String
Dim i, tmp(10)
Dim index As Variant
readReadMe msgtext
getMailRecipients tmp(), index
With frmMain
.MapiSess.DownLoadMail = False
.MapiSess.Action = mapSignOn
.List1.AddItem "Logging on to Mail Server"
.List1.ListIndex = .List1.ListCount - 1
.MapiMess.SessionID = .MapiSess.SessionID
For i = 1 To index
.MapiMess.Action = mapCompose
.MapiMess.MsgNoteText = msgtext
.MapiMess.RecipAddress = tmp(i)
.MapiMess.Action = mapSend
Next
.List1.AddItem "Completed mail message"
.MapiSess.Action = mapSignOff
.List1.AddItem "Mail sent."
.List1.ListIndex = .List1.ListCount - 1
End With
End Sub
Sub getMailRecipients(s(), m)
Dim i, j, x
Dim a$, tmp
i = FreeFile
Open "\fiche\mail_recipients.txt" For Input As i
x = 0
Do While Not EOF(i)
Line Input #i, a$
x = x + 1
s(x) = a$
Loop
m = x
If m = 0 Then
GoTo bad_inputfile
End If
Exit Sub
bad_inputfile:
MsgBox "Cannot send mail. MAIL_RECPIENTS.TXT has no adressees.", vbOKOnly
End Sub
Enter your message below
Sign in or Join us (it's free).