Outlook 2007 Add-In - mailItem.To only available after hitting a breakpoint and looking at value manually

StackOverflow https://stackoverflow.com/questions/19038084

  •  29-06-2022
  •  | 
  •  

Pregunta

I am making an outlook plugin in visual studio and part of it requires gathering the recipients/subject/body content. I am able to gather the subject and body without problem but accessing mailItem.To I always find it's blank.

body = mailItem.Body
subject = mailItem.Subject
Dim readtest As String = mailItem.To

Is the code I am using, and what makes it worse is that if I put a breakpoint in before trying to populate readtest and then I manually just look at the mailItem.To value and resume or step through the code it will work just fine.

Does anyone know how I can get this working properly?

¿Fue útil?

Solución

You could try to get the same functionality with mailItem.Recipients property. It returns IEnumerable. Recipient object have a Name member so basically you could do the following (It's in C# but i think you could figure it out with vb):

string recipients = string.Empty;
foreach (Outlook.Recipient r in mailItem.Recipients)
{
   recipients += r.Name + ";";
}

You should get the same result as if you use mailItem.To

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top