diff --git a/README.md b/README.md
index 8aa6dda8647b9a4b9814a92680ecfdbb0c0da71a..c5a73164e4d6e4f801013bc29e506a117a0736d2 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,7 @@ It requires the following CPAN distributions:
 * List-MoreUtils
 * Locale-Maketext-Lexicon
 * Log-Any
+* MIME-Lite
 * Rose-DB-Object
 * Template-Toolkit
 * Text-CSV
diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm
index 40c3b1549a03f78f1cfd8a14482c0fe6c099cbb5..73b6296a27d3dbfd2922708fc953bbd5eb6b3bbe 100644
--- a/lib/AccountManager/App.pm
+++ b/lib/AccountManager/App.pm
@@ -5,10 +5,11 @@ use warnings;
 
 use CGI;
 use DateTime;
-use Encode;
 use English qw(-no_match_vars);
+use Encode;
 use Log::Any::Adapter;
 use List::MoreUtils qw(uniq);
+use MIME::Lite;
 use Template;
 use Template::Constants qw(:chomp);
 use Text::CSV;
@@ -573,28 +574,14 @@ sub req_complete_challenge {
         );
     }
 
-    my $sender    = $self->{configuration}->{mailer}->{from};
-    my $sendmail  = $self->{configuration}->{mailer}->{sendmail_path} ||
-                    '/usr/sbin/sendmail';
-    my $recipient = $self->{in}->{email};
-
-    open(my $handle, '|-', "$sendmail -f $sender $recipient") or do {
-        $self->{logger}->errorf("Unable to run sendmail executable: %s", $ERRNO);
-        $self->respond(
-            template => 'errors.tt2.html',
-            data     => {
-                errors  => [ "mail_notification_error" ]
-            }
-        );
-    };
-
+    # build content
+    my $content;
     my $tt2 = Template->new({
         ENCODING     => 'utf8',
         PRE_CHOMP    => CHOMP_ONE,
         INCLUDE_PATH => $self->{configuration}->{setup}->{templates_dir} . "/mail",
-        FILTERS      => { mime => [ sub { return encode("MIME-Header", $_[0]); }, 0 ] },
     });
-    my $template = 'send_authentication_token.tt2.eml';
+    my $template = 'send_authentication_token.tt2.txt';
     my $data = {
         app => {
             url           => $self->{configuration}->{app}->{url},
@@ -602,17 +589,28 @@ sub req_complete_challenge {
             version       => $self->{configuration}->{app}->{version},
         },
         sourceip  => $ENV{REMOTE_ADDR},
-        from      => $sender,
-        to        => $recipient,
+        to        => $self->{in}->{email},
         entityid  => $self->{in}->{entityid},
         token     => $token->token(),
-        lh         => $self->{lh},
+        lh        => $self->{lh},
     };
+    $tt2->process($template, $data, \$content);
+
+    # wrap content in message
+    my $message = MIME::Lite->new(
+        From      => sprintf('eduGAIN Access Check <%s>', $self->{configuration}->{mailer}->{from}),
+        To        => $self->{in}->{email},
+        Subject   => encode("MIME-Header", sprintf('[eduGAIN Access Check] %s', $self->{lh}->maketext("Test accounts request"))),
+        Type      =>'text/plain',
+        Data      => $content,
+    );
 
-    binmode($handle, ":utf8");
-
-    unless ($tt2->process($template, $data, $handle)) {
-        $self->{logger}->errorf("Mail notification error: %s", $tt2->error());
+    # send message
+    eval {
+        $message->send_by_sendmail();
+    };
+    if ($EVAL_ERROR) {
+        $self->{logger}->errorf("Mail notification error: %s", $EVAL_ERROR);
         $self->respond(
             template => 'errors.tt2.html',
             data     => {
@@ -621,8 +619,6 @@ sub req_complete_challenge {
         );
     }
 
-    close $handle;
-
     $self->{logger}->infof(
         "Token send to %s for entityid=%s;token=%s",
         $self->{in}->{email},
diff --git a/templates/Makefile.am b/templates/Makefile.am
index 641da5e39bb9fe966987feda5e7b9b1c0d27b460..9a18e241f13e915003fc0696ef6adf5f7f66464e 100644
--- a/templates/Makefile.am
+++ b/templates/Makefile.am
@@ -1,6 +1,6 @@
 nobase_templates_DATA = \
 	accounts/accounts.php.tt2 \
-	mail/send_authentication_token.tt2.eml \
+	mail/send_authentication_token.tt2.txt \
 	web/errors.tt2.html \
 	web/home.tt2.html \
 	web/index.tt2.html \
@@ -10,7 +10,7 @@ nobase_templates_DATA = \
 	web/complete_challenge.tt2.html \
 	web/create_accounts.tt2.html \
 	renater/accounts/accounts.php.tt2 \
-	renater/mail/send_authentication_token.tt2.eml \
+	renater/mail/send_authentication_token.tt2.txt \
 	renater/web/errors.tt2.html \
 	renater/web/home.tt2.html \
 	renater/web/index.tt2.html \
diff --git a/templates/mail/send_authentication_token.tt2.eml b/templates/mail/send_authentication_token.tt2.txt
similarity index 83%
rename from templates/mail/send_authentication_token.tt2.eml
rename to templates/mail/send_authentication_token.tt2.txt
index ca2a3735bca032e02b91d02d83070913fbd5fc74..179001cf20980a77fac3a508f8514dcf42a7657b 100644
--- a/templates/mail/send_authentication_token.tt2.eml
+++ b/templates/mail/send_authentication_token.tt2.txt
@@ -1,8 +1,3 @@
-From: eduGAIN Access Check <[% from %]>
-To: [% to %]
-Subject: eduGAIN Access Check - [% lh.maketext("Test accounts request") | mime %]
-Content-type: text/plain; charset=UTF-8; format=flowed
-
 [% lh.maketext("This is an email challenge automatically sent to you by eduGAIN Access Check.") %]
 [% lh.maketext("Somebody with IP address [_1] has requested to create test accounts for eduGAIN Service Provider with entityID [_2].", sourceip, entityid) %]
 [% lh.maketext("The address [_1] is mentioned in the eduGAIN metadata as a contact for this Service Provider.", to) %]
diff --git a/templates/renater/mail/send_authentication_token.tt2.eml b/templates/renater/mail/send_authentication_token.tt2.txt
similarity index 83%
rename from templates/renater/mail/send_authentication_token.tt2.eml
rename to templates/renater/mail/send_authentication_token.tt2.txt
index ca2a3735bca032e02b91d02d83070913fbd5fc74..179001cf20980a77fac3a508f8514dcf42a7657b 100644
--- a/templates/renater/mail/send_authentication_token.tt2.eml
+++ b/templates/renater/mail/send_authentication_token.tt2.txt
@@ -1,8 +1,3 @@
-From: eduGAIN Access Check <[% from %]>
-To: [% to %]
-Subject: eduGAIN Access Check - [% lh.maketext("Test accounts request") | mime %]
-Content-type: text/plain; charset=UTF-8; format=flowed
-
 [% lh.maketext("This is an email challenge automatically sent to you by eduGAIN Access Check.") %]
 [% lh.maketext("Somebody with IP address [_1] has requested to create test accounts for eduGAIN Service Provider with entityID [_2].", sourceip, entityid) %]
 [% lh.maketext("The address [_1] is mentioned in the eduGAIN metadata as a contact for this Service Provider.", to) %]