Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

cant send email via code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    cant send email via code

    I have code sending an email through a shared email service.

    I set it up per instructions and when I do the test email, it works fine and I am getting it to the email sending to.

    When the code kicks off, I am getting an error: There was an error while sharing the share service email: "the calling thread must be STA, because many UI components require this."

    Any idea?

    I searched this and found a few threads but no resolultions I can find

    #2
    Hello, thanks for writing in. Are you starting any new threads in any of your scripts? Please also let me know which share service are you using so I can test the same on my end.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello, thanks for writing in. Are you starting any new threads in any of your scripts? Please also let me know which share service are you using so I can test the same on my end.
      No, I am not starting any new threads, just a simple send email. I am using GMAIL, if you need any other info let me know

      Comment


        #4
        Hi, please check the Spam folder of your "to" inbox as I found my test email in there. I tested on a linked Google account for the share service and have a simple script that is sending the email properly without this message about threading, please run this on your system to test if it works as well. I am running the latest version of the platform, If you have not yet gone to this upgrade yet please test the latest version. If you need a guide on upgrading just let me know and I will post it here. If you have not already, try removing and re-adding the share service and test again. If all else fails, you will need to test this on a clean installation of NinjaTrader or on a different PC if possible.


        Code:
        namespace NinjaTrader.NinjaScript.Indicators
        {
            public class TestSendMail : Indicator
            {
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
        
                        Name                                        = "TestSendMail";
                        Calculate                                    = Calculate.OnBarClose;
        
                    }
                    else if (State == State.Configure)
                    {
                    }
                }
        
                protected override void OnBarUpdate()
                {
                    if(State == State.Realtime)
                    {
                        SendMail("<enter email here>", "TEST", "TEST_CONTENT"); //run on 10 second bars, use simulated data feed. 
                    }
                }
            }
        }​
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChrisL View Post
          Hi, please check the Spam folder of your "to" inbox as I found my test email in there. I tested on a linked Google account for the share service and have a simple script that is sending the email properly without this message about threading, please run this on your system to test if it works as well. I am running the latest version of the platform, If you have not yet gone to this upgrade yet please test the latest version. If you need a guide on upgrading just let me know and I will post it here. If you have not already, try removing and re-adding the share service and test again. If all else fails, you will need to test this on a clean installation of NinjaTrader or on a different PC if possible.


          Code:
          namespace NinjaTrader.NinjaScript.Indicators
          {
          public class TestSendMail : Indicator
          {
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          
          Name = "TestSendMail";
          Calculate = Calculate.OnBarClose;
          
          }
          else if (State == State.Configure)
          {
          }
          }
          
          protected override void OnBarUpdate()
          {
          if(State == State.Realtime)
          {
          SendMail("<enter email here>", "TEST", "TEST_CONTENT"); //run on 10 second bars, use simulated data feed.
          }
          }
          }
          }​
          Thanks Chris, my code is basically the same exact mail just with my own message.

          Its not getting to spam folder, and I see the error I listed in first post every time it tries to send.

          When I go in to the share service through tools options, when I click test email, it makes me two factor authenticate each time, I am wondering if that has anything to do with it? Could this be a google setting I need to change?

          When I get the code texted to me and enter it, it sends the test email. I can't find any settings in gmail, and I do see NinjaTrader in my gmail options as having permissions to send emails

          Comment


            #6
            Hi Erik, Please try removing and re-adding the same account or use an alternate Google account. It may the 2FA preventing this, you can follow this guide to disable it:

            Your account is more secure when you need a password and a verification code to sign in. If you remove this extra layer of security, you will only be asked for a password when you sign in. It might be
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChrisL View Post
              Hi Erik, Please try removing and re-adding the same account or use an alternate Google account. It may the 2FA preventing this, you can follow this guide to disable it:

              https://support.google.com/accounts/...form%3DDesktop
              So the 2FA was actually not turned on, so it must not be that

              Comment


                #8
                Hi, This is not expected to happen and I am not able to reproduce this on the latest version of the platform, so this is local to your running environment. You will need to confirm what you have tried from my suggestions in my above post. Below are directions on how to set up a clean NinjaTrader user folder for testing:

                Close all running applications.

                Navigate to your Documents folder > Right-click on the 'NinjaTrader 8' folder > Rename > rename the folder to 'NinjaTrader 8 OLD'. DO NOT delete this folder.

                Now update to the latest version of NinjaTrader, To update to the latest version of NinjaTrader Desktop please follow the steps below.
                • Login into the NinjaTrader Account Dashboard (https://account.ninjatrader.com/)
                • Click "Download" in the bottom left-hand corner of the sidebar
                • Next select "Download" in the "Most Recent Release" Window in the main screen
                • Once the installation had downloaded, ensure any previous version of NinjaTrader is closed before running the installation package.
                • Note: You may need to locate this in your "Downloads" folder in a Windows File Explorer

                After the installation package is completed you will be able to log into NinjaTrader Desktop with the connection guide linked below.

                (https://support.ninjatrader.com/s/ar...language=en_US)


                This will generate a brand new "NinjaTrader 8" folder in the Documents. This is where all your user data is stored, just uninstalling from the Control Panel will not modify this folder. To revert back to your old installation, rename "NinjaTrader 8" to "NinjaTrader 8PREV" and rename "NinjaTrader 8OLD" back to "NinjaTrader 8" NinjaTrader looks for a folder called "NinjaTrader 8" in the documents to operate and store user data.
                If the above does not work still, you will need to test on a different PC.

                Kind regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChrisL View Post
                  Hi, This is not expected to happen and I am not able to reproduce this on the latest version of the platform, so this is local to your running environment. You will need to confirm what you have tried from my suggestions in my above post. Below are directions on how to set up a clean NinjaTrader user folder for testing:



                  If the above does not work still, you will need to test on a different PC.

                  Kind regards,
                  -ChrisL
                  Chris, I just upgraded to the latest version of NT8 a few weeks ago. I am not sure what is going on here, but its certainly not working. Are you saying there is something on this particular computer that is causing this? Like a firewall issue, or something else? I don't have another pc to really test on

                  Comment


                    #10
                    Hi Erik, I could not say exactly what is causing this but it is local to your PC since this is not happening on any other PC's/installations of the platform. As a workaround, you can try setting the ApartmentState manually:
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      If anyone runs into this, I got this resolved. It seems as though the share service for email configuration has changed from when I originally created this share service in one of the upgrades. I had to remove the share service and re-configure it, the credential process is different. Once I removed the original share service and created a new one, it started working fine

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by iceman2018, Today, 05:07 PM
                      0 responses
                      0 views
                      0 likes
                      Last Post iceman2018  
                      Started by rhyminkevin, Today, 04:58 PM
                      0 responses
                      17 views
                      0 likes
                      Last Post rhyminkevin  
                      Started by lightsun47, Today, 03:51 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post lightsun47  
                      Started by 00nevest, Today, 02:27 PM
                      1 response
                      14 views
                      0 likes
                      Last Post 00nevest  
                      Started by futtrader, 04-21-2024, 01:50 AM
                      4 responses
                      49 views
                      0 likes
                      Last Post futtrader  
                      Working...
                      X