Automated email generation not resolving multiple recipients

北城余情 提交于 2019-12-02 10:17:27

问题


I have a VBA script which creates & saves Draft emails. To add recipients, it pulls a string from a linked Excel table and adds that to the Recipients object.

For emails with single recipients, this works like a charm. All the user needs to do is open the draft, spend 5 seconds looking it over, and hit Send.

The problem occurs with several contacts at once (e.g. "a@aol.com; b@aol.com; c@aol.com"). When the user hits Send, Outlook will pop up a Check Names dialogue with no suggestions. The user can get around this by clicking on the To field and entering a dummy semicolon to trigger the auto resolve. I'd like to avoid this since this process creates well over a hundred emails at a time which need to be individually reviewed.

Looking around on the net, I've found and tried Recipients.ResolveAll which returns false. I suspect the reason is that Outlook is trying to resolve the entire string of recipients at once and not individually. So my question is: how do I get Outlook to stop displaying this Check Names dialogue? Do I need to loop thru my email string and parse out the individual emails?

Sub CreateEmail(id as Integer)
    Dim OlApp As Outlook.Application
    Dim ObjMail As Outlook.MailItem
    Dim Recipients As Outlook.Recipients
    Dim CurrentRecipient As Outlook.Recipient

    Set OlApp = CreateObject("Outlook.Application")
    Set ObjMail = OlApp.CreateItem(olMailItem)
    Set Recipients = ObjMail.Recipients

    Dim StrEmailTo As String
    StrEmailTo = CurrentDb.OpenRecordset( _
        "Select [Emails] from LU_Contacts where id=" & id & ";").Fields(0)

    Set CurrentRecipient = Recipients.Add(StrConv(StrEmailTo, 3))
    CurrentRecipient.Type = olTo
    ...

    Objmail.Save

回答1:


Recipients.Add takes a single email address.

If you wish to have multiple recipients, call Recipients.Add for each one.

If your string is returned in a ; delimited format, then something like:

dim EmailList as variant
dim NumEmails as long
dim AddEmailLoop as long

EmailList=split(StrEmailTo,";")
NumEmails=UBound(EmailList)

For AddEmailLoop=0 to NumEmails
    Recipients.add(EmailList(AddEmailLoop))
next

should allow you to add the entire list



来源:https://stackoverflow.com/questions/13019651/automated-email-generation-not-resolving-multiple-recipients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!