PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Interoperability
Attachments.Add throws Exception
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Interoperability
Attachments.Add throws Exception
![]() |
Attachments.Add throws Exception |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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" <ferdl@gmx.at> wrote in message news:OduGsV6kGHA.1320@TK2MSFTNGP04.phx.gbl... >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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Sue Mosher [MVP-Outlook] wrote:
> 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. > Thanks, that clarifies the problem a little bit. There Is no Way of copying the mails, since the mails can contain several attachments. Some are personalized attachments (with different Filenames of course) and some attachments are the same for each recipient. So is there any other way of adding one attachment to each email (always the same attachment) without copying the mails, and without getting one temp file created for each email. Thanks, Ferdinand |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Not that I know of.
-- 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" <ferdl@gmx.at> wrote in message news:4496BDC5.9080701@gmx.at... > Sue Mosher [MVP-Outlook] wrote: > >> 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. >> > > Thanks, that clarifies the problem a little bit. > > There Is no Way of copying the mails, since the mails can contain > several attachments. Some are personalized attachments (with different > Filenames of course) and some attachments are the same for each > recipient. So is there any other way of adding one attachment to each > email (always the same attachment) without copying the mails, and > without getting one temp file created for each email. > > Thanks, Ferdinand |
|
|
|
#5 |
|
Guest
Posts: n/a
|
I found a way with copying an initial Mailobject and customizing it
afterwards. The common Attachment remains the same. The problem now is, that if I save such a mail (one that is not newly created but copied from an initial mail) it is saved in the outbox instead of drafts. Anything I can do to solve that problem? Cheers Ferdinand Sue Mosher [MVP-Outlook] wrote: > Not that I know of. > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
A message winds up in the Outbox either because it was sent or because it was moved there from some other folder. Did you send instead of save? Did you copy a message that was already sent? Is there any reason why you can't just move it to Drafts if that's where you ultimately want it to be?
-- 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" <ferdl@gmx.at> wrote in message news:4496D144.8070700@gmx.at... >I found a way with copying an initial Mailobject and customizing it > afterwards. The common Attachment remains the same. > The problem now is, that if I save such a mail (one that is not newly > created but copied from an initial mail) it is saved in the outbox > instead of drafts. Anything I can do to solve that problem? > > Cheers > Ferdinand > > Sue Mosher [MVP-Outlook] wrote: > >> Not that I know of. >> |
|
|
|
#7 |
|
Guest
Posts: n/a
|
I fixed the problem.
A copy of an unsaved message is saved in the outbox when calling msg.Save() If the message is a copy of a saved message then it is saved to drafts when calling msg.Save() The next strange problem I found is, that when outlook is not started before interacting with it, messages are by default saved in the Inbox(!!!) when calling the msg.Save() method. When it is already started before creating mails messages are saved in the drafts folder. Is there any way of starting outlook and waiting until it is started before creating any emails? By the time I am getting used to all the strange behaviour of Outlook. temp filenames that are restricted to 100 files with the same original filename, all that strange folder behaviour... Sue Mosher [MVP-Outlook] wrote: > A message winds up in the Outbox either because it was sent or because it was moved there from some other folder. Did you send instead of save? Did you copy a message that was already sent? Is there any reason why you can't just move it to Drafts if that's where you ultimately want it to be? > |
|
|
|
#8 |
|
Guest
Posts: n/a
|
That depends on what you mean by "started." If you want to wait for the main Outlook window to appear, keep track of Explorers.Count.
-- 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" <ferdl@gmx.at> wrote in message news:4497C581.6060301@gmx.at... >I fixed the problem. > A copy of an unsaved message is saved in the outbox when calling msg.Save() > If the message is a copy of a saved message then it is saved to drafts > when calling msg.Save() > > The next strange problem I found is, that when outlook is not started > before interacting with it, messages are by default saved in the > Inbox(!!!) when calling the msg.Save() method. > When it is already started before creating mails messages are saved in > the drafts folder. > Is there any way of starting outlook and waiting until it is started > before creating any emails? > > By the time I am getting used to all the strange behaviour of Outlook. > temp filenames that are restricted to 100 files with the same original > filename, all that strange folder behaviour... > > > Sue Mosher [MVP-Outlook] wrote: > >> A message winds up in the Outbox either because it was sent or because it was moved there from some other folder. Did you send instead of save? Did you copy a message that was already sent? Is there any reason why you can't just move it to Drafts if that's where you ultimately want it to be? >> |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

