diff --git a/apps/log_monitor/src/mailer.erl b/apps/log_monitor/src/mailer.erl index 39f7a40..94cd7bd 100644 --- a/apps/log_monitor/src/mailer.erl +++ b/apps/log_monitor/src/mailer.erl @@ -14,6 +14,7 @@ %% API -export([start_link/0]). +-export([test/0]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, @@ -35,6 +36,26 @@ start_link() -> gen_server:start_link(?MODULE, [], []). +%%-------------------------------------------------------------------- +%% @doc +%% Send an email to test the configuration. +%% +%% @spec test() -> binary() | {error, Type, Message} +%% @end +%%-------------------------------------------------------------------- +test() -> + {ok, EmailConfig} = application:get_env(log_monitor, email_config), + Sender = proplists:get_value(sender, EmailConfig), + AdminReceiver = proplists:get_value(admin_receiver, EmailConfig), + Connection = proplists:get_value(connection, EmailConfig), + Subject = "Test", + error_logger:info_msg("Sender: ~s, Receiver: ~s, Subject: ~s~n", [Sender, AdminReceiver, Subject]), + gen_smtp_client:send_blocking( + {Sender, [AdminReceiver], + io_lib:format("Subject: ~s\r\nFrom: ~s\r\n\r\nTest~n", [Subject, Sender])}, + Connection + ). + %%%=================================================================== %%% gen_server callbacks %%%===================================================================