PC Review


Reply
Thread Tools Rate Thread

Attachments.Add throws Exception

 
 
Ferdinand Zaubzer
Guest
Posts: n/a
 
      19th Jun 2006
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
 
Reply With Quote
 
 
 
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      19th Jun 2006
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

 
Reply With Quote
 
Ferdinand Zaubzer
Guest
Posts: n/a
 
      19th Jun 2006
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
 
Reply With Quote
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      19th Jun 2006
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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

 
Reply With Quote
 
Ferdinand Zaubzer
Guest
Posts: n/a
 
      19th Jun 2006
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.
>

 
Reply With Quote
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      19th Jun 2006
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>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.
>>

 
Reply With Quote
 
Ferdinand Zaubzer
Guest
Posts: n/a
 
      20th Jun 2006
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?
>

 
Reply With Quote
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      20th Jun 2006
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>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?
>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
EndReceiveFrom throws exception. TN Microsoft C# .NET 1 19th Sep 2008 08:47 PM
Outlook Interop: Attachments.Add throws Exception Ferdinand Zaubzer Microsoft Outlook VBA Programming 1 19th Jun 2006 03:10 PM
SMTP throws exception =?Utf-8?B?RWQgQ2hpdQ==?= Microsoft ASP .NET 3 3rd Mar 2005 06:37 PM
PictureBox Bug, throws exception. =?Utf-8?B?Q2FtaWxvIFRlbGxlcw==?= Microsoft Dot NET Framework Forms 1 11th Apr 2004 10:52 PM
ServiceController throws exception Strider Microsoft Dot NET Framework 1 3rd Nov 2003 02:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:50 PM.