1
Cannot create new gateway with error "Please correct highlighted fields"
Problem reported by Andreas Hadjivasili - 7/22/2024 at 1:53 AM
Resolved
Hello, 
I have installed the latest version of smarterMail Build 8965 and i am trying to create a new gateway/failover. Once i press the save button i am getting an error "Please correct highlighted fields" while all fields are filled and nothing is highlighted. i need your help.
Thank you 

5 Replies

Reply to Thread
0
Zach Sylvester Replied
Employee Post
Hey Andreas, 

Thank you for reaching out! This happens because of the domain field input. To work around this switch the type to domain forward then enter a random domain in the domain field like asdasd.com. After this switch it back to backup mx and click save. This will be fixed in the next version. 

Thank you!
Zach Sylvester Software Developer SmarterTools Inc. www.smartertools.com
0
Andreas Hadjivasili Replied
Hello Zach, thank you for the answer.
Although, i am trying to create a new outbound (round robin) gateway not a backup MX. I followed your suggestion and created a new domain forward and then change it to outbound (round robin) but it is not changing with error " object reference not set to an instance of an object ".

Thank you in advance
0
Zach Sylvester Replied
Employee Post
Hey Andreas, 

This will be fixed in the next version. But in the meantime, you can use this API script to do this. 

import requests
import time
import random

def auth(username, password, url):
    authurl = url + "/api/v1/auth/authenticate-user"
    myobj = {'username': username, 'password': password}
    try:
        data = requests.post(authurl, json=myobj, timeout=5)
        data.raise_for_status()  # Raise an exception for HTTP errors
        refreshToken = data.json().get('refreshToken')
        accessToken = data.json().get('accessToken')
        accessTokenExpiration = data.json().get('accessTokenExpiration')
        access_info = {
            'accessToken': accessToken, 
            'accessTokenExpiration': accessTokenExpiration, 
            'refreshToken': refreshToken
        }
        return access_info
    except requests.exceptions.RequestException as e:
        print(f"Connection error: {e}")
        return None

def gateway_put(url, access_info):
    gatewayurl = url + "/api/v1/settings/sysadmin/gateway-put"
    headers = {
        'Authorization': f"Bearer {access_info['accessToken']}"
    }
    myobj = {"gatewayConfig":{"id":None,"address":"1.1.1.1","port":465,"shouldAuthenticate":False,"authUsername":"","authPassword":"","encryptionType":0,"type":0,"description":"","isSmarterMailServer":False,"smUrl":"","smUserName":"","smPassword":"","isEnabled":True,"verifyConnection":False}}

    try:
        response = requests.post(gatewayurl, json=myobj, headers=headers, timeout=5)
        return response.status_code
    except requests.exceptions.RequestException as e:
        print(f"Connection error: {e}")
        return None

if __name__ == "__main__":
    url = "http://localhost:17017"
    username = "admin"
    password = "admin"

    print(f"Attempting to authenticate user: {username}")

    access_info = auth(username, password, url)
    if access_info:
        print("Successfully authenticated.")
        print(f"Access Info: {access_info}")

        status_code = gateway_put(url, access_info)
        if status_code == 200:
            print("Successfully sent gateway configuration.")
        else:
            print(f"Failed to send gateway configuration with status code {status_code}")
    else:
        print("Authentication failed.")

    print("Process completed.")

To run the script, first, ensure that Python is installed on your computer. You can download it from python.org. Next, install the required `requests` library by using the command `pip install requests`. Save the provided script into a file named `script.py`. Open your command prompt (Windows) or terminal (macOS/Linux), navigate to the directory where `script.py` is saved, and run the script by typing `python script.py`.

You can edit the URL, username, and password directly in the script in the `__main__` block. For example, change the `url` variable to your server's URL, and update the `username` and `password` variables with your credentials. The authentication function uses the `authurl` endpoint, which combines the `url` with `"/api/v1/auth/authenticate-user"`. The gateway configuration function uses the `gatewayurl` endpoint, combining the `url` with `"/api/v1/settings/sysadmin/gateway-put"`. The headers include the `accessToken` for authorization, and the `myobj` variable contains the JSON object sent in the POST request.

You can edit the values of `myobj` within the `gateway_put` function to match your desired configuration, such as changing the `address`, `port`, `authUsername`, `authPassword`, and other settings. By following these instructions, you should be able to run the script and modify it to suit your needs.

Let me know if you have any questions. 

Thanks, 


Zach Sylvester Software Developer SmarterTools Inc. www.smartertools.com
0
Andreas Hadjivasili Replied
Hello again Zach and thank you very much for the help and the quick response. 
The script worked perfectly and i created the new gateway. Consider this thread as Done!
Thank you again!
1
Zach Sylvester Replied
Employee Post
Hey Andreas, 

I'm happy I could help! As I said in the next version this issue is resolved. 😊

Kind Regards, 

Zach Sylvester Software Developer SmarterTools Inc. www.smartertools.com

Reply to Thread