3

I'm trying to send e-mail from our ERP system. I tried using SMTP but it only works for internal mail and fails for external mail complaining about unable to relay or something. I think the manager either doesn't want to or know how to configure Exchange properly.

So my boss told me to use Outlook. The problem is my code works fine in debug but fails if Outlook is open, which it will be in almost every case. I did get it to work my modifying the vendors installation, but we would prefer not to do that. We are using Intuitive ERP 8.5. It stores its library files in the standard folder and there is a custom folder for any custom code or inherited vendor objects.

Program Files\IntuitiveERP.exe Program Files\IntuitiveERP\Custom Program Files\IntuitiveERP\Standard

If I put the program directory on the root of C: and combine the standard and custom folders the code works whether Outlook is open or closed. We would prefer not to modify the vendor's installation because if may cause problems with updates.

'Fails with Cannot create ActiveX component. objOutlook = CType(CreateObject("Outlook.Application"), Outlook.Application) 'Fails with Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005. objOutlook = New Outlook.Application mobjEmail = CType(objOutlook.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem) With mobjEmail .CC = strEmployeeEmail .Subject = String.Format(Constants.RFQ.Email.Subject, strRFQID) .To = strTo .Body = Constants.RFQ.Email.Body .Attachments.Add(String.Format(Constants.RFQ.Output.FullPath, strRFQID)) .Display(True) End With 

Any idea how to get a reference to Outlook when its open? Any alternative solutions?

7
  • If SMTP failed, what gives you the idea that Outlook won't? Commented Jul 15, 2016 at 20:23
  • 1
    Don't use Outlook. That's such a hack. Then Outlook needs to be installed wherever your app runs. Use SMTP and tell them to configure the relays in Exchange. It is what it is (and it's not too tricky, to be honest). Commented Jul 15, 2016 at 20:23
  • 1
    @Ares -- Because SMTP requires explicit relays to be "allowed" in Exchange due to security concerns to prevent rogue software from bouncing mail off your server. Outlook is different; it's designed to work with Exchange in a AD domain setting, and it doesn't use SMTP. Commented Jul 15, 2016 at 20:24
  • If it is designed to use Outlook, it will be susceptible to breaking any time an Office or Windows update is installed. Use the SMTP method if at all possible. Commented Jul 15, 2016 at 20:53
  • @Ares, because I witnessed Outlook work. Commented Jul 19, 2016 at 13:31

1 Answer 1

2

You can try this:

Try objOutlook = Marshal.GetActiveObject("Outlook.Application") Catch ex As Exception objOutlook = CType(CreateObject("Outlook.Application"), Outlook.Application) End Try 

Note that there are issues when running inside Visual Studio as Administrator and accessing Outlook when it is already running in user mode. See this. Try just running the EXE directly from the bin folder (don't run as administrator).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, you pointed to one of the problems I am having. The ERP software needs to be run as administrator. Getting a reference to Outlook (running in user mode) fails. This is why it works if Outlook is closed first. This may help me to get my boss to configure out Exchange properly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.