D
DanHood
Hi,
I am currently creating Add-in using Visual Studio Tools for Office which
will automate following manual actions:
attachment of the excel file with the unique name (eg excel file starting
with MLC word)
and sending it to multiple number of email address that have unique name +
number logic (eg MLC1, MLC2,)
At this stage I have resolved two most important issues : mapping the
recipients with corresponding files and mappin Z:\ directory to SharePoint so
as to open the communication between OutlookAddin and DocumentLibrary(stored
excel files) . I have tested it with small fund sample and it takes aroun
1.5-2 second to send an email with appropriate attachments to desired
recipient. That's good, but what if there is 156 recipients?
Do I really have to create Outlook Addin with almost 12 000 lines of code,
as I would be just copying general parts of the code and just changing search
entries or it is possible to create a global property or Array List etc that
would actually reduce the need for copying of the code all over again. I
will show you code in VB.Net as I am not sure which of two (vb.net, c#) you
use in your code projects, and let me observe that GetFiles really does
outstanding job, and its introduction in Net 2.0 framework was more than
welcome. I would highly appreciate if your suggestions are not mare general
words but are followed up with general code sample.
Imports Office = Microsoft.Office.Core
Imports System.Xml
Imports System.IO
Imports System.Configuration
Imports System.Collections
Imports System.Net.Mail
Imports System.Web
public class ThisApplication
Private WithEvents _Explorers As Outlook.Explorers
Private WithEvents _Explorer As Outlook.Explorer
Private _contactFolder As Outlook.Explorer
Private _mapiContact As Outlook.MAPIFolder
Private _helpMenuIdex As Object
Private _menuBar As Office.CommandBar
Private WithEvents _Email As Outlook.MailItem
Private Const COMMAND_BAR As String = "EDC"
Private Const BUTTON_NAME As String = "Send_EDC"
Private WithEvents myButton As Office.CommandBarButton
Private Const folder As String = "Z:\GeneratedForms\2006-08"
Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
_menuBar = Me.ActiveExplorer().CommandBars.Add(COMMAND_BAR,
Office.MsoBarPosition.msoBarTop, False, True)
_menuBar.Visible = True
myButton =
CType(_menuBar.Controls.Add(Office.MsoControlType.msoControlButton,
Type.Missing, Type.Missing, Type.Missing, True), Office.CommandBarButton)
myButton.Caption = BUTTON_NAME
myButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
myButton.Enabled = True
End Sub
Private Sub myButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles myButton.Click
Try
Call SendEmailtoContacts()
Catch ex As Exception
ex.ToString()
End Try
End Sub
Public Sub SendEmailtoContacts()
Dim objContactItem As Outlook.ContactItem
Dim outlookNameSpace As Outlook.NameSpace = Me.GetNamespace("MAPI")
Dim subjectEmail As String = "EDC"
Dim bodyEmail As String = "text"
'create and instance of the contact folder
Try
_mapiContact =
outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
For Each objContactItem In _mapiContact.Items.Restrict("[CompanyName] =
Intech")
CreateEmailItem(subjectEmail, objContactItem.Email1Address, bodyEmail,
"EDC_IMD_Forms")
Next
Catch objexc As Exception
objexc.ToString()
Finally
End Try
End Sub
Private Sub CreateEmailItem(ByVal subjectEmail As String, _
ByVal toEmail As String, ByVal bodyEmail As String, _
ByVal AttachmentFiles As String)
Dim eMail As Outlook.MailItem = Me.CreateItem _
(Outlook.OlItemType.olMailItem)
With eMail
..Subject = subjectEmail
..To = toEmail
..Body = bodyEmail
..Importance = Outlook.OlImportance.olImportanceLow
For Each foundFile As String In My.Computer.FileSystem.GetFiles( folder,
FileIO.SearchOption.SearchTopLevelOnly, "Aberdeen*.*")
..Attachments.Add(foundFile)
Next
..Send()
End With
End Sub
I am currently creating Add-in using Visual Studio Tools for Office which
will automate following manual actions:
attachment of the excel file with the unique name (eg excel file starting
with MLC word)
and sending it to multiple number of email address that have unique name +
number logic (eg MLC1, MLC2,)
At this stage I have resolved two most important issues : mapping the
recipients with corresponding files and mappin Z:\ directory to SharePoint so
as to open the communication between OutlookAddin and DocumentLibrary(stored
excel files) . I have tested it with small fund sample and it takes aroun
1.5-2 second to send an email with appropriate attachments to desired
recipient. That's good, but what if there is 156 recipients?
Do I really have to create Outlook Addin with almost 12 000 lines of code,
as I would be just copying general parts of the code and just changing search
entries or it is possible to create a global property or Array List etc that
would actually reduce the need for copying of the code all over again. I
will show you code in VB.Net as I am not sure which of two (vb.net, c#) you
use in your code projects, and let me observe that GetFiles really does
outstanding job, and its introduction in Net 2.0 framework was more than
welcome. I would highly appreciate if your suggestions are not mare general
words but are followed up with general code sample.
Imports Office = Microsoft.Office.Core
Imports System.Xml
Imports System.IO
Imports System.Configuration
Imports System.Collections
Imports System.Net.Mail
Imports System.Web
public class ThisApplication
Private WithEvents _Explorers As Outlook.Explorers
Private WithEvents _Explorer As Outlook.Explorer
Private _contactFolder As Outlook.Explorer
Private _mapiContact As Outlook.MAPIFolder
Private _helpMenuIdex As Object
Private _menuBar As Office.CommandBar
Private WithEvents _Email As Outlook.MailItem
Private Const COMMAND_BAR As String = "EDC"
Private Const BUTTON_NAME As String = "Send_EDC"
Private WithEvents myButton As Office.CommandBarButton
Private Const folder As String = "Z:\GeneratedForms\2006-08"
Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
_menuBar = Me.ActiveExplorer().CommandBars.Add(COMMAND_BAR,
Office.MsoBarPosition.msoBarTop, False, True)
_menuBar.Visible = True
myButton =
CType(_menuBar.Controls.Add(Office.MsoControlType.msoControlButton,
Type.Missing, Type.Missing, Type.Missing, True), Office.CommandBarButton)
myButton.Caption = BUTTON_NAME
myButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
myButton.Enabled = True
End Sub
Private Sub myButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles myButton.Click
Try
Call SendEmailtoContacts()
Catch ex As Exception
ex.ToString()
End Try
End Sub
Public Sub SendEmailtoContacts()
Dim objContactItem As Outlook.ContactItem
Dim outlookNameSpace As Outlook.NameSpace = Me.GetNamespace("MAPI")
Dim subjectEmail As String = "EDC"
Dim bodyEmail As String = "text"
'create and instance of the contact folder
Try
_mapiContact =
outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
For Each objContactItem In _mapiContact.Items.Restrict("[CompanyName] =
Intech")
CreateEmailItem(subjectEmail, objContactItem.Email1Address, bodyEmail,
"EDC_IMD_Forms")
Next
Catch objexc As Exception
objexc.ToString()
Finally
End Try
End Sub
Private Sub CreateEmailItem(ByVal subjectEmail As String, _
ByVal toEmail As String, ByVal bodyEmail As String, _
ByVal AttachmentFiles As String)
Dim eMail As Outlook.MailItem = Me.CreateItem _
(Outlook.OlItemType.olMailItem)
With eMail
..Subject = subjectEmail
..To = toEmail
..Body = bodyEmail
..Importance = Outlook.OlImportance.olImportanceLow
For Each foundFile As String In My.Computer.FileSystem.GetFiles( folder,
FileIO.SearchOption.SearchTopLevelOnly, "Aberdeen*.*")
..Attachments.Add(foundFile)
Next
..Send()
End With
End Sub