fbpx
Welcome, Guest
Username: Password: Remember me
Welcome to the XSharp forum!

Tell us and our members who you are, what you like and why you became a member of this site.
We welcome all new members and hope to see you around a lot!
  • Page:
  • 1
  • 2

TOPIC: Trying send mails and attachments via Outlook

Trying send mails and attachments via Outlook 16 Mar 2019 14:03 #7786

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 40
  • 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 := ""
    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

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 14:27 #7787

  • lumberjack's Avatar

  • lumberjack


  • Posts: 680
  • 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
    George, South Africa

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 15:29 #7788

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2232
  • Hi Raymond,

    I had to change the code a bit, but for me sending mails works.
    This is my code actually:
    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 := ""
    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):

    File Attachment:

    File Name: OutlookTester.zip
    File Size:2 KB


    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 16:41 #7790

  • Chris's Avatar

  • Chris


  • Posts: 1878
  • Please also include what error you are getting!
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 16:44 #7791

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 40
  • 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

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 16:47 #7792

  • Chris's Avatar

  • Chris


  • Posts: 1878
  • 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.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    Trying send mails and attachments via Outlook 16 Mar 2019 16:48 #7793

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2232
  • Hi Raymond,
    please look at my "catch" statement:
    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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 17:04 #7794

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 40
  • 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:

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 17:13 #7795

  • Chris's Avatar

  • Chris


  • Posts: 1878
  • 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?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 17:15 #7796

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2232
  • 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
    System.Execption

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 17:27 #7797

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 40
  • Hi Chris,
    Currently with all and I find it cumbersome because I have to scroll up and down to find the Methods.

    Chris I did not quite understand what I should exactly do to solve my outlook problem.
    I just posted Wolfgang that TRY shows an error. This is code that is currently working. Only when I add the Outlook:interop I then get the erros and I have a lot of Try and catch routine in my source code.

    Regards,
    Raymond

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 17:31 #7798

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2232
  • Hi Raymond,

    it seems I'm ways too stupid to explain what your problem really is.

    Maybe it is too much to TRY to put
    catch oEx as System.Exception
    instead of
    catch oEx as Exception
    in your code?
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 17:33 #7799

  • lumberjack's Avatar

  • lumberjack


  • Posts: 680
  • Hi Wolfgang,

    wriedmann wrote: 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

    System.Execption

    He does have System.Excepton

    Don't you mean his CATCH statement should be:
    CATCH oEx AS Microsoft.Office.Interop.Outlook.Exception
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 17:35 #7800

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2232
  • Hi Raymond,
    unfortunately it seems you need a full explanation and I'm not experienced enough to do that.

    Microsoft has put a class called Exception in the Microsoft.Office.Interop.Outlook namespace, and if you include that interop, the compiler takes that class instead of the needed System.Exception class.

    Therefore, if you include the interop in your application, you NEED to specify the fully qualified class name.

    Maybe Vulcan has another sequence, but IMHO the X# compiler is right here.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 17:37 #7801

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2232
  • Hi Johan,

    the compiler is taking the exception class from the interop assembly, and that class cannot be used in the catch statement.

    When I tried to compile the code on my machine, it gave exactly the same error until I added the fully qualified class name.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 18:46 #7802

  • Chris's Avatar

  • Chris


  • Posts: 1878
  • Hi Rymond,

    Ah, I understand now, it's just that you need to compile the app first once. When you do that, then you should be able to use right-click for the GoTo Definition option to appear. Btw, you can also put the editor cursor on the method you want to go to its definition and press Alt+Right button, this searches by text and should get you to the method. Also you can use Alt + Left key for returning back.

    As for the compiler error, just change the code

    CATCH ex AS exception

    to

    CATCH ex AS System.Exception

    (there was a typo earlier)
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    Trying send mails and attachments via Outlook 16 Mar 2019 19:10 #7803

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 40
  • Hi Chris,
    Thanks form the Info will Try it all out.

    Raymond

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 16 Mar 2019 22:03 #7804

  • lumberjack's Avatar

  • lumberjack


  • Posts: 680
  • Guys,
    I think we sometimes (see how we battled with Jeff) don't have the full picture.

    I had the complete file and I believe what happened was this.
    The Vulcan code was:
    USING Microsoft.Office.Interop
    However, in the file as was send to me it had:
    USING Microsoft.Office.Interop.Excel // etc.
    I make my assumption because there were a lot of commented lines like:
    LOCAL oApp AS ApplicationClass
    //LOCAL oApp AS Excel.ApplicationClass
    Hence, in the "original" code, there was no way the compiler could get confused with which Exception to use. I think both Vulcan and X# treated it the same, there was however a difference how the USING statement was defined.

    Raymond, don't see this as directed against you. I just know from experience, my own Vulcan code compiled in 99% of cases as is, except where X# introduced something more strict, or highlighted a "bug" in Vulcan or where I had my own #command to emulate a feature that was not supported in Vulcan but was now standard in X#. Had to remove my # command and slightly adapt code to adhere to the X# implementation. One I can think of now was my #command around PROPERTY xxx AS INT GET SET y, slight difference in how I did it and how it was implemented in X#.

    Johan
    PS: Please check this and let us know the result.
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 17 Mar 2019 12:21 #7812

  • robert's Avatar

  • robert


  • Posts: 1678
  • Raymond,

    Make sure that the "bitness" of your app and outlook match: If you have a 32 bits version of outlook then you must also use a 32 bits (x86) version of your app. If your outlook is 64 bits then you will also need a 64 bits version of your app.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Trying send mails and attachments via Outlook 17 Mar 2019 12:51 #7813

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2232
  • Hi Robert,
    Fortunately you can overcome the bitness problem with COM.
    My sample works in 64 bit mode, and my Outlook 2010 is 32 bit.
    And COM is the only possibility to send emails through Outlook 64 bit from VO Applications.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1
    • 2