-
Dec 14th, 2010, 11:02 AM
#1
Thread Starter
New Member
application to send e-mail - trouble making it use both Office 2010 and 2007
Hi
I have written an application which uses the Outlook object library to send an e-mail with information from a textbox. I programmed this on Windows 7 and Office 2010, which was a mistake as most of the clients will be using Windows XP and Office 2007. I am getting an error when running the application on Windows XP/2007:
Code:
Could not load file or assembly 'Microsoft.Office.Interop.Outlook, Version=14.0.0.0 .... etc
I understand that this is because I have not loaded the Outlook 12.0 assemblies, however I am having trouble adding the assemblies on my Win7/2010 programming machine. I have downloaded the standalone Office 2007 PIAs however the Outlook 12.0 doesnt appear on the list, and when I try and add just the Office 12.0 I get an error.
is there a way to standardise and make the application work with both 2007 and 2010 outlook machines? I think it is possible, I have read some articles making the application choose the correct version, however cannot figure out how to.
Any help would be much appreciated. Thanks
-
Dec 14th, 2010, 02:30 PM
#2
Re: application to send e-mail - trouble making it use both Office 2010 and 2007
Do not have an answer for your problem but perhaps an alternative if you are only sending messages and do not need Outlook specific features look at http://www.systemnetmail.com/ which is simple to use class and this site has excellent examples to get you going in no time.
-
Dec 14th, 2010, 08:41 PM
#3
Re: application to send e-mail - trouble making it use both Office 2010 and 2007
If you want to actually interact with Outlook, e.g. your sent message gets stored in the Outlook Sent Items folder, then you will have to do as you are. If you don't need that sort of thing then you would, as suggested, be better off just doing it yourself in code using System.Net.Mail. For a simple scenario, it's just a few lines of code. Here's some code from an ASP.NET MVC application of my own:
vb.net Code:
Private mailServer As New SmtpClient(WebConfigurationManager.AppSettings("MailServer")) Private fromAddress As String = WebConfigurationManager.AppSettings("MailFromAddress") Public Sub New() Me.mailServer.UseDefaultCredentials = False Me.mailServer.Credentials = New NetworkCredential(Me.fromAddress, WebConfigurationManager.AppSettings("MailPassword")) End Sub Public Sub SendMail(ByVal toAddress As String, ByVal subject As String, ByVal body As String, ByVal ParamArray attachments As String()) Using message As New MailMessage(Me.fromAddress, toAddress, subject, body) For Each file In attachments message.Attachments.Add(New Attachment(file)) Next Me.mailServer.Send(message) End Using End Sub
This is the bulk of the code from a class that encapsulates mail functionality.
If you do need to stick with Outlook, either reference the actual version you intend to use during development or, if you need to support multiple versions, you must use late-binding. For multiple versions, you usually start out by referencing a specific version but make sure to only use features that are available in all versions you intend to support. Once you're done, you remove the reference and then fix all the resulting errors by using late-binding.
For more information, find the user profile for member RobDog888 and check out the resources in his signature. He's the local Office Guru.
-
Dec 15th, 2010, 03:34 PM
#4
Thread Starter
New Member
Re: application to send e-mail - trouble making it use both Office 2010 and 2007
Hi guys, thanks for the replies!
No i dont need to use outlook specifically, it was just the first thing I thought of and I didnt realise that VB provided classes to do what I needed!
having a look now at the system.net.mail class and think ive got a solution in place - which in fact should be better than the outlook one
thanks
-
Dec 15th, 2010, 04:15 PM
#5
Re: application to send e-mail - trouble making it use both Office 2010 and 2007
Originally Posted by duffman69
Hi guys, thanks for the replies!
No i dont need to use outlook specifically, it was just the first thing I thought of and I didnt realise that VB provided classes to do what I needed!
having a look now at the system.net.mail class and think ive got a solution in place - which in fact should be better than the outlook one
thanks
Good to hear the .NET SMTP email methods fit your needs.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|