I have a list of about 50 email recipients i am trying to send an email to.
The list is generated first as a text file with ; after each email - which i subsequently transform into a string which
forms the LCTO list. I am wondering if the string is too long and if it should be formatted in a different way -
if so how would i alter the code bleow to make this work.
thanks for your help.
k
Dimension aryAttach(1) && Add as many elements (attachments) as you like
Local lcFrom, lcTo, lcSubject, lcBody, lnCount, lcCC, lcBCC, lcUserName, lcPassword, llEmailStatus, lcErrorHandlerWas
aryAttach(1) = 'SAMPLE.txt' && File to attach, add more if needed
lcFrom = "
me@myemail.com"
=STRTOFILE(CHRTRAN(FILETOSTR("semail.txt"),CHR(26),''),"semail.txt") && gets rid of box at end of text file
lcto =filetostr('semail.txt')
lcBCC = " "
lcUserName = "" && Only if required by default smtp server
lcPassword = "" && Only if required by default smtp server
*************************************************************
lcSubject = "Respond to this Notice"
lcBody =filetostr('othersample.txt')
lcErrorHandlerWas = On("ERROR")
Wait Window " One Moment... Email is being generated and sent " Nowait
llEmailStatus = SendViaMAPI(lcFrom, lcTo, lcSubject, lcBody, @aryAttach, lcCC, lcBCC, lcUserName, lcPassword)
On Error &lcErrorHandlerWas
Wait Clear
If llEmailStatus
Messagebox("Your message to " + lcTo + " has been sent.",64,"EMAIL SENT SUCCESSFULLY VIA MAPI")
Else
Messagebox("YOUR MESSAGE WAS NOT SENT")
Endif
**********************************************************************
Function SendViaMAPI(tcFrom, tcTo, tcSubject, tcBody, taFiles, tcCC, tcBCC, tcUserName, tcPassword)
**********************************************************************
#Define Primary 1
#Define CARBON_COPY 2
#Define BLIND_CARBON_COPY 3
Local loSession, loMessages
On Error Return(.F.)
loSession = Createobject("MSMAPI.MAPISession")
If Type('tcUserName') = 'C'
loSession.UserName = tcUserName
Endif
If Type('tcPassword') = 'C'
loSession.Password = tcPassword
Endif
loSession.Signon()
If (loSession.SessionID > 0)
loMessages = Createobject( "MSMAPI.MAPIMessages" )
loMessages.SessionID = loSession.SessionID
Endif
With loMessages
.Compose()
.RecipDisplayName = tcTo
.RecipType = Primary
.ResolveName()
If Type("tcCC") = "C" And !Empty(tcCC)
.RecipIndex = .RecipCount
.RecipDisplayName = tcCC
.RecipType = CARBON_COPY
.ResolveName()
Endif
If Type("tcBCC") = "C" And !Empty(tcBCC)
.RecipIndex = .RecipCount
.RecipDisplayName = tcBCC
.RecipType = BLIND_CARBON_COPY
.ResolveName()
Endif
If Type('taFiles',1) = "A"
For lnCountAttachments = 1 To Alen(taFiles)
.AttachmentIndex = .AttachmentCount
.AttachmentPathName = taFiles(lnCountAttachments)
Endfor
Endif
.MsgSubject = tcSubject
.MsgNoteText = tcBody
* .MsgNoteHtml = tcBody
* oMail.contenttype='html'
.Send(.T.)
Endwith
loSession.Signoff()
Store .Null. To loSession, loMessages
Release loSession, loMessages
Return .T.
Endfunc