Sending email via outlook, using late binding

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have this reference to another thread
http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/9293d268-9c14-477f-ade6-dd1a77c96260 http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/9293d268-9c14-477f-ade6-dd1a77c96260
Thank you Louis.fr for a nice concise reply.
In that thread, you gave a good answer from which I constructed the following working code
<pre class="prettyprint dynamic outlookReference = Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application"));
dynamic mailItem = outlookReference.CreateItem(0);

mailItem.To = "a@b.c;d@e.f;g@h.etc;";
mailItem.Subject = "rhubarb rhubarb rhubarb rhubarb";
mailItem.Body = "custard custard custard custard custard";
mailItem.Attachments.Add("filePath.xyz");
mailItem.Send();
[/code]
However, my client has three email accounts defined in his Outlook and this mail item must use the third account as the
From address.
How do I specify mailItem.From?<br/>
(I tried msg.From but it isnt defined. Then I tried CreateItem(2)
but that didnt work either.)
What does the prameter (0) do for CreateItem?
Is their some documentation on this dynamic linkage to Outlook?
I would appreciate any help anyone can give.

View the full article
 
Back
Top