- # warn "using driver: $driver to send message to $params->{'destination'}";
-
- # Create a sender
- my $sender = SMS::Send->new( $driver,
- _login => C4::Context->preference('SMSSendUsername'),
- _password => C4::Context->preference('SMSSendPassword'),
- );
-
- # Send a message
- my $sent = $sender->send_sms( to => $params->{'destination'},
- text => $params->{'message'},
- );
+ my ($sent, $sender);
+
+ my $subpath = $driver;
+ $subpath =~ s|::|/|g;
+
+ my $sms_send_config = C4::Context->config('sms_send_config');
+ my $conf_file = defined $sms_send_config
+ ? File::Spec->catfile( $sms_send_config, $subpath )
+ : $subpath;
+ $conf_file .= q{.yaml};
+
+ my %args;
+ if ( -f $conf_file ) {
+ require YAML;
+ my $conf = YAML::LoadFile( $conf_file );
+ %args = map { q{_} . $_ => $conf->{$_} } keys %$conf;
+ }
+
+ eval {
+ # Create a sender
+ $sender = SMS::Send->new(
+ $driver,
+ _login => C4::Context->preference('SMSSendUsername'),
+ _password => C4::Context->preference('SMSSendPassword'),
+ %args,
+ );
+
+ # Send a message
+ $sent = $sender->send_sms(
+ to => $params->{destination},
+ text => $params->{message},
+ );
+ };
+
+ #We might die because SMS::Send $driver is not defined or the sms-number has a bad format
+ #Catch those errors and fail the sms-sending gracefully.
+ if ($@) {
+ warn $@;
+ return;
+ }