question

Spclate-4029 avatar image
1 Vote"
Spclate-4029 asked WaqasQayyum-5921 published

Sending multiple Outlook emails with vb script

Hi all,

New to VBScripting and have a question on my script. I have a CSV which has 3 columns (subject, email address, Body). I'm do a while lop to open the csv and read in the lines and while not at the end of the stream send an email. Issue is that its only sending the first email then erroring with
173508-image.png



Any ideas?
Code is below

 Dim olApp
 Dim objMailItem
 Dim arr,strLine
 Const ForReading = 1
 strInput = "C:\Scripts\mails.csv"
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set olApp = CreateObject("Outlook.Application")
 Set objMailItem = olApp.CreateItem(0)
 Set inputFile = fso.OpenTextFile(strInput, ForReading)
    
 Do While Not inputFile.AtEndOfStream
     arr = Split(inputFile.ReadLine, ",")
     objMailItem.Subject = arr(0)
     objMailItem.To = arr(1)
     objMailItem.Body = arr(2) 
     objMailItem.Send
 Loop
 Set olApp = Nothing
 Set objMailItem = Nothing


dotnet-visual-basic
image.png (19.8 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I solved it. I was creating the Outlook object only once outside the loop. Schoolboy mistake.

0 Votes 0 ·

I have the same issue can you please share your full coding please?

0 Votes 0 ·

I have the same issue can you please share your full coding please?

0 Votes 0 ·

0 Answers