Can't send mail using smtp

:- use_module(library(smtp)).

a :-
    smtp_send_mail(
         'semen.shanin@gmail.com',
          send_message,
        [ security(ssl),
          port(465),
          host('smtp.gmail.com'),
          auth('semen.shanin@gmail.com'-'ifdv wtok hcwl risz'),
          from('semen.shanin@gmail.com')
        ]
     ).

send_message(Out) :-
        format(Out, 'Hi Alice,\n\n', [  ]),
        format(Out, 'Want to go out tonight?\n\n', [  ]),
        format(Out, '\tCheers, Bob\n', [   ]).

library(smtp) works and i tested connection on SMTP Test Tool, it works too. But when i start script, i get Errors:

“ERROR: Socket error: Connection refused
ERROR: In:
ERROR: [19] socket:tcp_connect((0000015238ae0a40),localhost:465)
ERROR: [18] setup_call_catcher_cleanup(smtp:tcp_socket((0000015238ae0a40)),smtp:tcp_connect((0000015238ae0a40),…),_7610,smtp:error_cleanup(_7644,…)) at c:/program files/swipl/boot/init.pl:679
ERROR: [16] smtp:smtp_open(localhost:465,_7678,_7680,[auth(…),…|…]) at c:/users/cxmv/appdata/local/swi-prolog/pack/smtp/prolog/smtp.pl:201
ERROR: [15]
ERROR: [14] sig_atomic(smtp:smtp_open(…,_7764,_7766,…))
ERROR: [13] setup_call_catcher_cleanup(smtp:smtp_open(…,_7810,_7812,…),smtp:do_send_mail(_7824,_7826,‘semen.shanin@gmail.com’,…,…),_7796,smtp:smtp_close(_7842,_7844)) at c:/program files/swipl/boot/init.pl:678
ERROR: [9] toplevel_call(user:user:a) at c:/program files/swipl/boot/toplevel.pl:1173
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.”

Docs say this should be smtp('smtp.gmail.com'). Default is localhost, which may explain why it is complaining why it cannot connect to localhost:465 :slight_smile:

1 Like

I tried it but now it works, thank you so much.