Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
olaoyesunday1
Contributor III
Contributor III

Sending Email to More than Two Recipients Using Qlikview Macros through Outlook

Dear All,

Anytime I am sending emails to more than two recipients, the macros would give this error "that "Outlook does not recognize one or more names. " and it would highlight objMail.Send in my code. here is my  code: 

Sub mSendMail(pdfFilePath)
Dim objOutlk
Dim objMail
Const olMailItem = 0

' Check if Outlook is already running
On Error Resume Next
Set objOutlk = GetObject(, "Outlook.Application")
On Error GoTo 0

' If Outlook is not running, start it
If (objOutlk = "") Then
StartOutlook
' Wait for 5 seconds for Outlook to start
ActiveDocument.GetApplication.Sleep 5000

' Create a new instance of Outlook application
Set objOutlk = CreateObject("Outlook.Application")
End If


' Create a new mail item
Set objMail = objOutlk.createitem(olMailItem)

' Recipient's email address
objMail.To = "example@yahoo.com"

objMail.Cc = "example2@gmail.com"

' Subject of the email
objMail.Subject = "Testing " & Date()

' Body of the email
objMail.HTMLBody = "Body of the email, This is an automatic generated email from QlikView."

' Add attachment (use the generated PDF file)
objMail.Attachments.Add pdfFilePath

' Send the email
objMail.Send

' Release resources
Set objMail = Nothing
Set objOutlk = Nothing
End Sub

if I add BCc to the ' Recipient's email address it would complain : 

' Recipient's email address
objMail.To = "example@yahoo.com"

objMail.Cc = "example2@gmail.com"

objMail.BCc = "example3@abc.com" or I added two email to the cc like this 

Recipient's email address
objMail.To = "example@yahoo.com"

objMail.Cc = "example2@gmail.com, example7@abc.com" it would say  "Outlook does not recognize one or more names. " and it would highlight objMail.Send in my code. here is my  code, 

Please, what can I do to be sending emails to more than 10recipients at the same time .

Thanks

Labels (3)
6 Replies
Sebastian_Linser

marcus_sommer

Beside using n single recipients you may also use mailing lists.

Further useful might be to load the recipients from external sources which are then assigned to variables or used in table-boxes which are read from the macro.

olaoyesunday1
Contributor III
Contributor III
Author

@Sebastian_Linser and @marcus_sommer  thanks very much , but when I used the right separator ";"  in my code like this ' Recipient's email address
objMail.To = "olaolu567@yahoo.com"
objMail.Cc = "codedevelopment72@gmail;tolu@smatdata.com"  it was still saying the same error: "Outlook does not recognize one or more names. " and highlighting objMail.Send.

marcus_sommer

Be careful by relying the cursor-position or highlighting anything as the cause of the error. Such approach will work well within VBA but not mandatory within the modul-editor of the QlikView VBS implementation.

A good workaround would be to use some msgbox within the code - just with values like 1, 2, 3 to see until which point the code runs and in the next check you may move the msgbox a bit up/down until you could surely identify the error-line. By a bit more complex code you may also track the various variables, paths, iterations and so on with the msgbox.

If the cause behind the error is further unclear you may add before the line an:

On Error Resume Next

and afterwards a:

msgbox err.number & " - " & err.description

which may provide valuable hints for a further investigating.

olaoyesunday1
Contributor III
Contributor III
Author

@marcus_sommer when I tried 

On Error Resume Next

and afterwards a: 

msgbox err.number & " - " & err.description, it display -2147467269 - Outlook does not recognize one or more names. 

But I observed one thing when I used only one domain like this:                                                              ' Recipient's email address
objMail.To = "olu@yahoo.com"
objMail.Cc = "ola@yahoo.com;dove@yahoo.com;dola@yahoo.com"
objMail.BCC = "coke@yahoo.com; kola@yahoo.com"

It sent without any error.

marcus_sommer

Such behaviour might be caused by any configurations and/or security settings which may enforce a resolving of the recipients against any lists/contacts or not allowing more as one domain at a time or similar stuff - any maybe not only directly from Outlook else also from the related Exchange server.

Of course there are again a lot of hints to this kind of issue: -2147467269 - Outlook does not recognize one or more names

If you couldn't practically solve this you may to consider to skip the approach with n recipients within a single mail and looping through the list of recipients and each one gets it own mail.

Beside of all the above you may need to get in touch with your IT department because there may various rules in place to restrict the number of recipients and mails per time and further conditions.