Results 1 to 5 of 5

Thread: application to send e-mail - trouble making it use both Office 2010 and 2007

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    10

    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

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,274

    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:
    1. Private mailServer As New SmtpClient(WebConfigurationManager.AppSettings("MailServer"))
    2. Private fromAddress As String = WebConfigurationManager.AppSettings("MailFromAddress")
    3.  
    4. Public Sub New()
    5.     Me.mailServer.UseDefaultCredentials = False
    6.     Me.mailServer.Credentials = New NetworkCredential(Me.fromAddress, WebConfigurationManager.AppSettings("MailPassword"))
    7. End Sub
    8.  
    9. Public Sub SendMail(ByVal toAddress As String, ByVal subject As String, ByVal body As String, ByVal ParamArray attachments As String())
    10.     Using message As New MailMessage(Me.fromAddress, toAddress, subject, body)
    11.         For Each file In attachments
    12.             message.Attachments.Add(New Attachment(file))
    13.         Next
    14.  
    15.         Me.mailServer.Send(message)
    16.     End Using
    17. 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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    10

    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

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Re: application to send e-mail - trouble making it use both Office 2010 and 2007

    Quote Originally Posted by duffman69 View Post
    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
  •  



Click Here to Expand Forum to Full Width