init method
Setup the appender. This needs to be called for every appender to configure the appender with the necessary data.
Implementation
@override
Future<void>? init(Map<String, dynamic> config, bool test, DateTime? date) {
created = date ?? DateTime.now();
type = AppenderType.EMAIL;
if (config.containsKey('level')) {
level = Level.fromString(config['level']);
} else {
level = Level.INFO;
}
if (config.containsKey('dateFormat')) {
dateFormat = config['dateFormat'];
} else {
dateFormat = Appender.defaultDateFormat;
}
if (config.containsKey('host')) {
host = config['host'];
} else {
throw ArgumentError('Missing host argument for EmailAppender');
}
if (config.containsKey('user')) {
user = config['user'];
}
if (config.containsKey('password')) {
password = config['password'];
}
if (config.containsKey('port')) {
port = config['port'];
} else {
throw ArgumentError('Missing port argument for EmailAppender');
}
if (config.containsKey('fromMail')) {
fromMail = config['fromMail'];
} else {
fromMail = user;
}
if (config.containsKey('fromName')) {
fromName = config['fromName'];
} else {
fromName = user;
}
if (config.containsKey('to')) {
to = [];
for (String s in config['to']) {
to.add(Address(s));
}
} else {
throw ArgumentError('Missing to argument for EmailAppender');
}
if (config.containsKey('toCC')) {
toCC = [];
for (String s in config['toCC']) {
toCC!.add(Address(s));
}
}
if (config.containsKey('toBCC')) {
toBCC = [];
for (String s in config['toBCC']) {
toBCC!.add(Address(s));
}
}
if (config.containsKey('ssl')) {
ssl = config['ssl'];
}
if (config.containsKey('html')) {
html = config['html'];
}
if (!test) {
_smtpServer = SmtpServer(host!,
port: port!, username: user, password: password, ssl: ssl!);
_connection = PersistentConnection(_smtpServer);
}
if (config.containsKey('templateFile')) {
templateFile = config['templateFile'];
var file = File(templateFile!);
template = file.readAsStringSync();
}
return null;
}