Check the contents of the %temp% folder. As you add attachments, Outlook creates temporary files there, but only up to fileName (99). You may, therefore, need to delete those temporary files if you're creating more than 100 messages containing the same attachment.
Alternatively, create one message containing the attachment, then use MailItem.Copy to return a copy of that message and send the copy.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"Ferdinand Zaubzer" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>I have a Problem of creating a large number of emails with attachments.
> Everything works fine, but when the 100th mail is created and the
> attachment is added
>
> mail.Attachments.Add(fileName, (int)OlAttachmentType.olByValue,
> mail.Body.Length + 1, "My Attachment");
>
> throws an Exception telling me the following: (Translated from German)
> The file <filename> cannot be created. Check the permissions of the
> folder where you want to create the file.
>
> The code for creating all the mails is the following:
>
> foreach (Recipient rec in Recipients){
> _MailItem mail = outlookApp.CreateItem(OlItemType.olMailItem);
>
> mail.To = rec.address;
> mail.Body = rec.body;
> mail.Subject = rec.subject;
>
> mail.Attachments.Add(rec.pathToAttachment,
> (int)OlAttachmentType.olByValue,
> mail.Body.Length + 1, "My Attachment");
>
> mail.Save();
> mails.Add(mail); //save mails references in an Arraylist to be
> able to send them later, after checking
> mails in Draftfolder.
> }
>
> Can anyone help me with this problem
> Thanks