diff --git a/apps/files_sharing/ajax/email.php b/apps/files_sharing/ajax/email.php index e931e5f77e..2a81e6f982 100644 --- a/apps/files_sharing/ajax/email.php +++ b/apps/files_sharing/ajax/email.php @@ -9,4 +9,9 @@ $subject = $user.' shared a '.$type.' with you'; $link = $_POST['link']; $text = $user.' shared the '.$type.' '.$_POST['file'].' with you. It is available for download here: '.$link; $fromaddress = OCP\Config::getUserValue($user, 'settings', 'email', 'sharing-noreply@'.OCP\Util::getServerHost()); -OCP\Util::sendMail($_POST['toaddress'], $_POST['toaddress'], $subject, $text, $fromaddress, $user); +try { + OCP\Util::sendMail($_POST['toaddress'], $_POST['toaddress'], $subject, $text, $fromaddress, $user); + OCP\JSON::success(); +} catch (Exception $exception) { + OCP\JSON::error(array('data' => array('message' => $exception->getMessage()))); +} diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index afe31a75d0..1ad5187354 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -202,11 +202,19 @@ OC.Share={ emailPrivateLink:function() { var link = $('#privateLinkText').val(); var file = link.substr(link.lastIndexOf('/') + 1).replace(/%20/g, ' '); - $.post(OC.filePath('files_sharing', 'ajax', 'email.php'), { toaddress: $('#email').val(), link: link, file: file } ); - $('#email').css('font-weight', 'bold'); - $('#email').animate({ fontWeight: 'normal' }, 2000, function() { - $(this).val(''); - }).val('Email sent'); + var email = $('#email').val(); + if (email != '') { + $.post(OC.filePath('files_sharing', 'ajax', 'email.php'), { toaddress: email, link: link, file: file }, function(result) { + if (result && result.status == 'success') { + $('#email').css('font-weight', 'bold'); + $('#email').animate({ fontWeight: 'normal' }, 2000, function() { + $(this).val(''); + }).val('Email sent'); + } else { + OC.dialogs.alert(result.data.message, 'Error while sharing'); + } + }); + } }, dirname:function(path) { return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); diff --git a/lib/mail.php b/lib/mail.php index a4e3a39fee..0ecee0f01c 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -83,7 +83,8 @@ class OC_Mail { unset($mailo); OC_Log::write('mail', 'Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject, OC_Log::DEBUG); } catch (Exception $exception) { - OC_Log::write('mail', $exception->getMessage(), OC_Log::DEBUG); + OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR); + throw($exception); } }