Sample "Sending emails with Python" not working in Windows

View thread

cmarsura

Hi, I am unable to run your basic example Sending emails with Python”  because nxlog is unable to load the required module.

Reducing the code to a minimal set, I found that nxlog is unable to load some basic Python modules that come bundled with the Python installation.

Following are some modules that nxlog is unable to load:

  • smtplib
  • socket
  • ssl
  • email.mime.text
  • windows_tools.users (after installing with "pip install windows_tools.users")

Same file modified to be executed directly from python.exe in same machine, runs correctly

nxlog.conf:

Panic Soft
#NoFreeOnExit TRUE

define ROOT     C:\Program Files\nxlog
define CERTDIR  %ROOT%\cert
define CONFDIR  %ROOT%\conf\nxlog.d
define LOGDIR   %ROOT%\data

include %CONFDIR%\\*.conf
define LOGFILE  %LOGDIR%\nxlog.log
LogFile %LOGFILE%

Moduledir %ROOT%\modules
CacheDir  %ROOT%\data
Pidfile   %ROOT%\data\nxlog.pid
SpoolDir  %ROOT%\data


<Extension python>
    Module      xm_python
    PythonCode   'c:\Program Files\nxlog\modules\extension\python\py\send_email.py'
</Extension>

<Input in>
   Module    im_null
</Input>

<Output out>
   Module    om_null
</Output>

<Processor myprocessor>
    Module pm_null
    <Exec>
        python_call('main');
   </Exec>
</Processor>

<Route myroute>
    Path    in => myprocessor => out
</Route>

send_email.py:

import smtplib
#import socket
#import ssl
#import email.mime.text

# pip install windows_tools.users
#import windows_tools.users as users


import json
import nxlog

#def main():
def main(event):
    # Body that does nothing
    print("Hello from Main()")

nxlog.log:

2023-12-28 11:45:26 ERROR Python ERROR: ImportError('DLL load failed while importing _socket: Impossibile trovare il modulo specificato.')
2023-12-28 11:45:26 ERROR #0 in <module> (...) at: C:\Program Files\Python310\Lib\socket.py:51;
2023-12-28 11:45:26 ERROR #1 in _call_with_frames_removed (...) at: <frozen importlib._bootstrap>:241;
2023-12-28 11:45:26 ERROR #2 in exec_module (...) at: <frozen importlib._bootstrap_external>:882;
2023-12-28 11:45:26 ERROR #3 in _load_unlocked (...) at: <frozen importlib._bootstrap>:685;
2023-12-28 11:45:26 ERROR #4 in _find_and_load_unlocked (...) at: <frozen importlib._bootstrap>:999;
2023-12-28 11:45:26 ERROR #5 in _find_and_load (...) at: <frozen importlib._bootstrap>:1025;
2023-12-28 11:45:26 ERROR #6 in <module> (...) at: C:\Program Files\Python310\Lib\smtplib.py:44;
2023-12-28 11:45:26 ERROR #7 in _call_with_frames_removed (...) at: <frozen importlib._bootstrap>:241;
2023-12-28 11:45:26 ERROR #8 in exec_module (...) at: <frozen importlib._bootstrap_external>:882;
2023-12-28 11:45:26 ERROR #9 in _load_unlocked (...) at: <frozen importlib._bootstrap>:685;
2023-12-28 11:45:26 ERROR #10 in _find_and_load_unlocked (...) at: <frozen importlib._bootstrap>:999;
2023-12-28 11:45:26 ERROR #11 in _find_and_load (...) at: <frozen importlib._bootstrap>:1025;
2023-12-28 11:45:26 ERROR #12 in <module> (...) at: C:\Program Files\nxlog\modules\extension\python\py\send_email.py:1;
2023-12-28 11:45:26 ERROR #13 in _call_with_frames_removed (...) at: <frozen importlib._bootstrap>:241;
2023-12-28 11:45:26 ERROR #14 in exec_module (...) at: <frozen importlib._bootstrap_external>:882;
2023-12-28 11:45:26 ERROR #15 in _load_unlocked (...) at: <frozen importlib._bootstrap>:685;
2023-12-28 11:45:26 ERROR #16 in _find_and_load_unlocked (...) at: <frozen importlib._bootstrap>:999;
2023-12-28 11:45:26 ERROR #17 in _find_and_load (...) at: <frozen importlib._bootstrap>:1025;
2023-12-28 11:45:26 ERROR Couldn't import python module 'send_email'
2023-12-28 11:45:26 INFO nxlog-ce-3.2.2329 started
2023-12-28 11:45:26 ERROR ### ASSERTION FAILED at line 503 in libnxpython.c/nx_python_init(): "conf->thread_state_key == NULL" ###

The environment is:

Windows Server 2022

nxlog-ce-3.2.2329

python-3.10.8-amd64.exe