Trying send mails and attachments via Outlook

We encourage new members to introduce themselves here. Get to know one another and share your interests.
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

Trying send mails and attachments via Outlook

Post 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
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Trying send mails and attachments via Outlook

Post 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?
______________________
Johan Nel
Boshof, South Africa
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Trying send mails and attachments via Outlook

Post 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 114 times
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4923
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Trying send mails and attachments via Outlook

Post by Chris »

Please also include what error you are getting!
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

Trying send mails and attachments via Outlook

Post 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
User avatar
Chris
Posts: 4923
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Trying send mails and attachments via Outlook

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Trying send mails and attachments via Outlook

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

Trying send mails and attachments via Outlook

Post 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.
Attachments
Compile_Error_Outlook_Interop.pdf
(351.77 KiB) Downloaded 102 times
User avatar
Chris
Posts: 4923
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Trying send mails and attachments via Outlook

Post 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?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Trying send mails and attachments via Outlook

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply