Picking up attachments from Outlook Compose window
<p>My Addin opens up in New Mail Window, and this is opened through Outlook as well as MAPI or mailTo. Now user can add attachment with this mail, but I send the mail through code (being my requirement), now I try to pick up attachments from current open new mail windows this way:-</p>

<pre><code>private Outlook.Attachments GetAttachments()
{
    Outlook.Inspector inspector = this.inspectorWrapper.Inspector;
    Outlook.MailItem myMailItem = (Outlook.MailItem)inspector.CurrentItem;
    var attachments = myMailItem.Attachments;
    return attachments;
}
</code></pre>

<p>Then During my Send Method I try to access it this way:-</p>

<pre><code>for (int i = 0; i &lt;= attachments.Count; i++)
{
    eMail.Attachments.Add(attachments[i].PathName, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1, attachments[i].FileName);
}
</code></pre>

<p>attachments is the same object returned through above method, it does show correct attachment count (e.g 2 in my example case).</p>

<p>But it throws an "index outside bounds of array error" when I try to access thisattachments[i] in the code snippet above.
Not sure why this occurs.</p>

<p>Any help will be greatly appreciated</p>

<p><strong>Edit:</strong></p>

<p>I open up the compose window, and attach files manually or from excel etc., then I try to fetch attachments from current New Mail Item inspector this way:-</p>

<pre><code>private Outlook.Attachments GetAttachments()
{
    Outlook.Inspector inspector = this.inspectorWrapper.Inspector;
    Outlook.MailItem myMailItem = (Outlook.MailItem)inspector.CurrentItem;
    var attachments = myMailItem.Attachments;
    return attachments;
}
</code></pre>

<p>I do get attachment count to be 2 when I attach two files and the name is also there when I'm trying to access it attachments[1].FileName but the path is coming to be null.
How can I save these attachments to the mail I'm trying to send pro grammatically?</p>