xsharp.eu • Trying send mails and attachments via Outlook
Page 1 of 3

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 1:03 pm
by rn@warner-it.com
Hi guys,
I am trying to port my Vulcan app that worked to X# however I get error after error. Currently my problem is Interop to Outlook. Could you please indicate what I need to upload for assistance? I had everything working in Viulcan.Net but strangely I get compile errors of
code thatz is running in my application the Try and Catch routines for Database I keep getting errors and cannot implement any mail features in X#. I cannot even get this simple code to run.


LOCAL oApp AS Microsoft.Office.Interop.Outlook.Application
LOCAL oAppt AS _MailItem
LOCAL oItemType AS OlItemType


oApp := Microsoft.Office.Interop.Outlook.Application{}

oItemType := OlItemType.OlMailitem
oAppt:= (_Mailitem)oApp:CreateItem(oItemtype)
*oContact := (ContactItem)oOutlook:CreateItem(oItemType)
*oAppt := oApp:CreateItem(oItemtype)

oAppt:@@To := "rn@warner-it.com"
oAppt:Subject := "Test Mail"
oAppt:Body := "Hello This is a Test Mail"
oAppt:Send()

// Clean up.
oApp := Null_oBject
oAppt := Null_oBject
When you icliude the outlook Interop this code below is show as errors and this code works well currently without Outlook.Interop
TRY
SELF:Tda:InsertCommand := OledbCommand{cStatement2, oConn1}
cmd := SELF:Tda:InsertCommand
cmd:ExecuteNonQuery()
*messagebox.show("Alle Daten Satze erfolgreich gelöscht !!!! ")

CATCH ex AS exception
messageBox.show("Fehler beim löschen !!! "+ex:Message:ToString())
END TRY
I would appreciaqte some help as I am currently stuck
Thanks and Regards
Raymond

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 1:27 pm
by lumberjack
Hi Raymond,
I am not that clued up with Interop and Outlook. Tried to help, but nothing from a non-Interop user that I can find fault with.
Guys? anybody that can help?

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 2:29 pm
by wriedmann
Hi Raymond,

I had to change the code a bit, but for me sending mails works.
This is my code actually:

Code: Select all

using Microsoft.Office.Interop.Outlook
using System.Windows.Forms

class OutlookApp

static method InteropOutlook() as void
local oApp as Microsoft.Office.Interop.Outlook.Application
local oAppt as _MailItem
local oItemType as OlItemType

oApp := Microsoft.Office.Interop.Outlook.Application{}

oItemType := OlItemType.OlMailitem
oAppt:= (_Mailitem)oApp:CreateItem(oItemtype)

oAppt:@@To := "wr@meles.net"
oAppt:Subject := "Test Mail"
oAppt:Body := "Hello This is a Test Mail"
oAppt:Send()
// Clean up.
oApp := Null_oBject
oAppt := Null_oBject
// When you icliude the outlook Interop this code below is show as errors and this code works well currently without Outlook.Interop

try
//self:Tda:InsertCommand := OledbCommand{cStatement2, oConn1}
//cmd := self:Tda:InsertCommand
//cmd:ExecuteNonQuery()
messagebox.show("Alle Daten Satze erfolgreich gelöscht !!!! ")

catch ex as System.exception
messageBox.show("Fehler beim löschen !!! "+ ex:Message:ToString())
end try

return

end class
I had to include MSOutl.DLL and System.Windows.Forms in my application.

The complete application is attached here (as XIDE export file):
OutlookTester.zip
(1.62 KiB) Downloaded 44 times
Wolfgang

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 3:41 pm
by Chris
Please also include what error you are getting!

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 3:44 pm
by rn@warner-it.com
Hello Wolfgang,
I am sorry to say that implementing your changes to my programme has had no impact it is still showing errors. I tried sending a mail from your example programme with my mail address and I am afraid I did not receive a mail.
Here is a screen shot of the error it is saying that my Try and catch routines are not valid when I include the Outlook. Interop. Can you please tell me what the solution can be ??

Thanks
Raymond
I still get the Try Catch errors I do not know why I am going to make a mini version of the programe and attach it to the current problem hope that is ok. Will give you an info after i finish.

Raymond

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 3:47 pm
by Chris
Raymond, unfortunately you forgot the attachment! Yes, of course it is OK to post here the app!

Edit: Ah, I see you sent it in an email. It's what Wolfgang said.

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 3:48 pm
by wriedmann
Hi Raymond,
please look at my "catch" statement:

Code: Select all

catch oEx as System.Exception
It seems the Microsoft.Office.Interop.Outlook namespace contains an Exception class that is not inherited from the System.Exception class that is needed for the catch statement.
Wolfgang

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 4:04 pm
by rn@warner-it.com
Hi Chris,
I am using your IDE that you created I have done this since Dieter introduced me to Vulcan.net. I have to also tell you that I cannot use
then current version to go to the methods with the right mouse click it does not give me the option. Anyway here is the error message.

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 4:13 pm
by Chris
Hi Raymond,

Please see Wolfgang's reply above, as he said, apparently the Outlook library defines an Exception class as well. To disambiguate, use System,.Exception as Wolfgang pointed out.

About right-click not showing "Go to definition", does this happen with all classes and methods? Or with specific ones?

Trying send mails and attachments via Outlook

Posted: Sat Mar 16, 2019 4:15 pm
by wriedmann
Hi Raymond,

please read my message!
The compile error message says it clearly: the Microsoft.Office.Interop.Outlook.Exception class cannot be used with a catch statement.
Therefore you need to fully qualify it as

Code: Select all

System.Execption
Wolfgang