how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
Go Back  Xtreme Visual Basic Talk > > > how to send multiple attachments through microsoft outlook??


Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2006, 09:34 AM
moumona moumona is offline
Newcomer
 
Join Date: Aug 2006
Posts: 13
Unhappy how to send multiple attachments through microsoft outlook??


hello everyone,
I have been working on this since yesterday but getting nowhere. if someone can help me here i would very much appreciate it.
i am working on a standalone application and from my application the user can send email with multiple attachments using outlook. well, i've been able to send single attachment by storing the path of the file in a string variable but when i try to store multiple filenames with path in a array list and loop through it to attach multiple attachments it gives me the following error:

An unhandled exception type 'System.Runtime.InteropServices.COMException' occurred in TEST.exe
Additional information: Can't find this file. Make sure the path and file name are correct.

my code:
Code:
' Create an Outlook application.
        Dim oApp As Outlook._Application
        oApp = New Outlook.Application

        ' Create a new MailItem.
        Dim oMsg As Outlook._MailItem
        oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
        oMsg.Subject = "Export Report from WIB"
        oMsg.Body = "This Email is from WIB sent on " & DateTime.Now & ". It   is an Export Report. Attached is the file." & " " & txtBody.Text & vbCr & vbCr
        oMsg.To = txtTo.Text
        Dim sSource As ArrayList = arlAttachments
        Dim oAttachs As Outlook.Attachments = oMsg.Attachments
        Dim i, iCnt As Integer
        iCnt = arlAttachments.Count - 1

        For i = 0 To iCnt

            oAttachs.Add(arlAttachments(i).ToString)
        Next
        ' Send
        oMsg.Send()

        ' Clean up
        oApp = Nothing
        oMsg = Nothing
        oAttachs = Nothing
Reply With Quote
  #2  
Old 11-15-2006, 12:36 PM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Hi,

I've recently started to 'port myself' from VB/VBA when it comes to VB.NET and Outlook.

Here is an example that may solve your issue:

Code:
Imports olApp = Microsoft.Office.Interop.Outlook Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim OutL As New olApp.Application Dim Mail As olApp.MailItem = _ CType(OutL.CreateItem(olApp.OlItemType.olMailItem), olApp.MailItem) Dim al As New ArrayList(2) Dim Counter As Integer al.Insert(0, "c:\Test.xls") al.Insert(1, "c:\Test1.xls") al.Insert(2, "c:\Test2.xls") With Mail .To = "Mr..." .Subject = "Attachments" .Body = "Message" For Counter = 0 To al.Count - 1 .Attachments.Add(Source:=al(Counter), DisplayName:=al(Counter)) Next .Save() .Send() End With Mail = Nothing OutL = Nothing End Sub End Class

In general I recommend you to take part of the following excellent source:
Programming Microsoft Outlook with Visual Studio .NET
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #3  
Old 11-15-2006, 01:03 PM
moumona moumona is offline
Newcomer
 
Join Date: Aug 2006
Posts: 13
Default

i tried what you mentioned but when i paste this in my code :
Imports olApp = Microsoft.Office.Interop.Outlook

i get the error-namespace or type 'outlook' for the imports 'micorsoft.office.interop.outlook' cannot be found
Reply With Quote
  #4  
Old 11-15-2006, 01:42 PM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

I forgot to mention that you need to add a reference to the PIA for Outlook.

This is done via the command Project | Add Reference... on the Menu in VB.NET and choose the Tab COM. Select the option 'Microsoft Outlook 11.0 Object Library or if you use XP 'Microsoft Outlook 10.0 Object Library.

If you don't have the PIA installed please check Mike_R's excellent write up VB.NET Office Automation FAQ
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #5  
Old 11-15-2006, 02:14 PM
moumona moumona is offline
Newcomer
 
Join Date: Aug 2006
Posts: 13
Default

i have allready referenced it. microsoft outlook 11.0 object library so what could be the problem? am i missing somethin?
Reply With Quote
  #6  
Old 11-15-2006, 02:57 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

I think that your Office 11.0 installation does not have the PIA's installed. You have two approaches here:

(1) The "preferred" approach is to install the Primary Interop Assembly (PIA) and then reference the PIA, which will be found in the GAC. The PIA's are installed automatically when Office 11.0 is installed, but as Dennis has noted in some other threads, they will not be installed automatically if the .NET Framework was not already installed when Office 11.0 was installed. To fix this, you should be able to go to Start > Control Panel > Add or Remove Programs and then complete the install for Office 11.0.

(2) You could continue using a custom, local Interop Assembly (IA) that Visual Studio has created for you already. This means that you would not use 'Imports Outlook = Microsoft.Office.Interop.Outlook' and directly call the Outlook types without an 'Outlook' name specifier. In short, if you took Dennis' code from above and removed:

(a) 'Imports olApp = Microsoft.Office.Interop.Outlook'

(b) All instances of 'olApp.'

The resulting code would look as follows, and should run:
Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim OutL As New Application Dim Mail As MailItem = _ CType(OutL.CreateItem(OlItemType.olMailItem), MailItem) Dim al As New ArrayList(2) Dim Counter As Integer al.Insert(0, "c:\Test.xls") al.Insert(1, "c:\Test1.xls") al.Insert(2, "c:\Test2.xls") With Mail .To = "Mr..." .Subject = "Attachments" .Body = "Message" For Counter = 0 To al.Count - 1 .Attachments.Add(Source:=al(Counter), DisplayName:=al(Counter)) Next .Save() .Send() End With Mail = Nothing OutL = Nothing End Sub End Class
That said, the MSFT-recommended approach is to use the PIA, so I think you should try to install the PIA as described above. Once that is done, you can open up your VS Project, remove the old reference to Outlook, and then add the reference back again, making sure that your added reference is indeed found in the GAC.

Hope this helps, and keep us posted!
,
Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #7  
Old 11-15-2006, 03:06 PM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Thanks Mike for helping him out
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #8  
Old 11-15-2006, 03:45 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Hey Dennis, let's hope...

But, you know, moumona, I'm not 100% sure that the code I gave you was correct. The advice on how to install the PIA's should be correct and I would do that.

However, to use the local IA instead of the PIA, I think you would need to omit the Imports statment and access the 'Outlook' namespace. (I omitted it in my code above). Without testing, I think that the following is correct:
Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim OutL As New Outlook.Application Dim Mail As Outlook.MailItem = _ CType(OutL.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem) Dim al As New ArrayList(2) Dim Counter As Integer al.Insert(0, "c:\Test.xls") al.Insert(1, "c:\Test1.xls") al.Insert(2, "c:\Test2.xls") With Mail .To = "Mr..." .Subject = "Attachments" .Body = "Message" For Counter = 0 To al.Count - 1 .Attachments.Add(Source:=al(Counter), DisplayName:=al(Counter)) Next .Save() .Send() End With Mail = Nothing OutL = Nothing End Sub End Class
Sorry for any confusion...

,
Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook?? how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
 
how to send multiple attachments through microsoft outlook??
how to send multiple attachments through microsoft outlook??
 
-->