mirror of
https://github.com/freescout-helpdesk/freescout.git
synced 2024-11-24 19:33:07 +01:00
Send email to user if user replied to notification from wrong email
This commit is contained in:
parent
3b22e51e09
commit
b7c58cb2d4
@ -22,6 +22,7 @@ class ActivityLog extends Activity
|
||||
const DESCRIPTION_EMAILS_SENDING_ERROR_TO_USER = 'error_sending_email_to_user';
|
||||
const DESCRIPTION_EMAILS_SENDING_ERROR_INVITE = 'error_sending_invite_to_user';
|
||||
const DESCRIPTION_EMAILS_SENDING_ERROR_PASSWORD_CHANGED = 'error_sending_password_changed';
|
||||
const DESCRIPTION_EMAILS_SENDING_WRONG_EMAIL = 'error_sending_wrong_email';
|
||||
const DESCRIPTION_EMAILS_FETCHING_ERROR = 'error_fetching_email';
|
||||
const DESCRIPTION_SYSTEM_ERROR = 'system_error';
|
||||
const DESCRIPTION_USER_DELETED = 'user_deleted';
|
||||
@ -49,6 +50,8 @@ class ActivityLog extends Activity
|
||||
return __('Error sending invitation email to user');
|
||||
case self::DESCRIPTION_EMAILS_SENDING_ERROR_PASSWORD_CHANGED:
|
||||
return __('Error sending password changed notification to user');
|
||||
case self::DESCRIPTION_EMAILS_SENDING_WRONG_EMAIL:
|
||||
return __('Error sending email to the user who replied to notiication from wrong email');
|
||||
case self::DESCRIPTION_EMAILS_FETCHING_ERROR:
|
||||
return __('Error fetching email');
|
||||
case self::DESCRIPTION_SYSTEM_ERROR:
|
||||
|
@ -323,10 +323,10 @@ class FetchEmails extends Command
|
||||
if (Email::sanitizeEmail($user->email) != Email::sanitizeEmail($from)) {
|
||||
$this->logError("From address {$from} is not the same as user {$user->id} email: ".$user->email);
|
||||
$message->setFlag(['Seen']);
|
||||
// todo: send email with information
|
||||
// Unable to process your update
|
||||
// Your email update couldn't be processed
|
||||
// If you are trying to update a conversation, remember you must respond from the same email address that's on your account. To send your update, please try again and send from your account email address (the email you login with).
|
||||
|
||||
// Send "Unable to process your update email" to user
|
||||
\App\Jobs\SendEmailReplyError::dispatch($from, $user, $mailbox)->onQueue('emails');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
87
app/Jobs/SendEmailReplyError.php
Normal file
87
app/Jobs/SendEmailReplyError.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* User replied from wrong email address to the email notification.
|
||||
*/
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Mail\UserEmailReplyError;
|
||||
use App\SendLog;
|
||||
use App\Thread;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Mail;
|
||||
|
||||
class SendEmailReplyError implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $from;
|
||||
|
||||
public $user;
|
||||
|
||||
public $mailbox;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($from, $user, $mailbox)
|
||||
{
|
||||
$this->from = $from;
|
||||
$this->user = $user;
|
||||
$this->mailbox = $mailbox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// Configure mail driver according to Mailbox settings
|
||||
\App\Misc\Mail::setMailDriver($this->mailbox);
|
||||
|
||||
$exception = null;
|
||||
try {
|
||||
Mail::to([['name' => '', 'email' => $this->from]])
|
||||
->send(new UserEmailReplyError());
|
||||
} catch (\Exception $e) {
|
||||
// We come here in case SMTP server unavailable for example
|
||||
activity()
|
||||
->withProperties([
|
||||
'error' => $e->getMessage().'; File: '.$e->getFile().' ('.$e->getLine().')',
|
||||
])
|
||||
->useLog(\App\ActivityLog::NAME_EMAILS_SENDING)
|
||||
->log(\App\ActivityLog::DESCRIPTION_EMAILS_SENDING_WRONG_EMAIL);
|
||||
|
||||
$exception = $e;
|
||||
}
|
||||
|
||||
$status_message = '';
|
||||
if ($exception) {
|
||||
$status = SendLog::STATUS_SEND_ERROR;
|
||||
$status_message = $exception->getMessage();
|
||||
} else {
|
||||
$failures = Mail::failures();
|
||||
|
||||
// Save to send log
|
||||
if (!empty($failures)) {
|
||||
$status = SendLog::STATUS_SEND_ERROR;
|
||||
} else {
|
||||
$status = SendLog::STATUS_ACCEPTED;
|
||||
}
|
||||
}
|
||||
|
||||
SendLog::log(null, null, $this->from, SendLog::MAIL_TYPE_WRONG_USER_EMAIL_MESSAGE, $status, null, $this->user->id, $status_message);
|
||||
|
||||
if ($exception) {
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,8 +10,6 @@ use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class AutoReply extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Conversation created by customer.
|
||||
*
|
||||
|
@ -11,8 +11,6 @@ use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class PasswordChanged extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* User to whom email is sent.
|
||||
*/
|
||||
|
@ -12,8 +12,6 @@ use Illuminate\Queue\SerializesModels;
|
||||
//abstract class AbstractMessage extends Mailable
|
||||
class ReplyToCustomer extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Conversation to send.
|
||||
*
|
||||
|
@ -8,7 +8,6 @@ use Illuminate\Mail\Mailable;
|
||||
|
||||
class Test extends Mailable
|
||||
{
|
||||
|
||||
public $mailbox;
|
||||
|
||||
/**
|
||||
|
33
app/Mail/UserEmailReplyError.php
Normal file
33
app/Mail/UserEmailReplyError.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* User replied from wrong email address to the email notification.
|
||||
*/
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserEmailReplyError extends Mailable
|
||||
{
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->subject(__('Unable to process your update'))
|
||||
->view('emails/user/email_reply_error');
|
||||
}
|
||||
}
|
@ -11,8 +11,6 @@ use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserInvite extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* User to whom invitation is sent.
|
||||
*/
|
||||
|
@ -8,8 +8,6 @@ use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserNotification extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Recipient.
|
||||
*
|
||||
|
@ -397,35 +397,30 @@ class Thread extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text for the assignee.
|
||||
* Get text for the assignee in line item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAssigneeName($ucfirst = false, $user = null, $self = true)
|
||||
public function getAssigneeName($ucfirst = false, $by_user = null)
|
||||
{
|
||||
if (!$by_user) {
|
||||
$by_user = auth()->user();
|
||||
}
|
||||
if (!$this->user_id) {
|
||||
if ($ucfirst) {
|
||||
return __('Anyone');
|
||||
} else {
|
||||
return __('anyone');
|
||||
}
|
||||
} elseif (($user && $this->user_id == $user->id) || (!$user && auth()->user() && $this->user_id == auth()->user()->id)) {
|
||||
|
||||
// Not using mb_ucfirst to avoid possible problems with encoding
|
||||
if ($ucfirst) {
|
||||
if ($self) {
|
||||
$name = __('Yourself');
|
||||
} else {
|
||||
$name = __('You');
|
||||
}
|
||||
} elseif ($by_user && $this->user_id == $by_user->id) {
|
||||
if ($this->created_by_user_id && $this->created_by_user_id == $this->user_id) {
|
||||
$name = __('yourself');
|
||||
} else {
|
||||
if ($self) {
|
||||
$name = __('yourself');
|
||||
} else {
|
||||
$name = __('you');
|
||||
}
|
||||
$name = __('you');
|
||||
}
|
||||
if ($ucfirst) {
|
||||
$name = ucfirst($name);
|
||||
}
|
||||
|
||||
return $name;
|
||||
} else {
|
||||
// User may be deleted
|
||||
@ -500,7 +495,7 @@ class Thread extends Model
|
||||
if ($this->action_type == Thread::ACTION_TYPE_STATUS_CHANGED) {
|
||||
$did_this = __("marked as :status_name conversation #:conversation_number", ['status_name' => $this->getStatusName(), 'conversation_number' => $conversation_number]);
|
||||
} elseif ($this->action_type == Thread::ACTION_TYPE_USER_CHANGED) {
|
||||
$did_this = __("assigned :assignee convsersation #:conversation_number", ['assignee' => $this->getAssigneeName(false, null, false), 'conversation_number' => $conversation_number]);
|
||||
$did_this = __("assigned :assignee convsersation #:conversation_number", ['assignee' => $this->getAssigneeName(false, null), 'conversation_number' => $conversation_number]);
|
||||
} elseif ($this->action_type == Thread::ACTION_TYPE_CUSTOMER_CHANGED) {
|
||||
$did_this = __("changed the customer to :customer in conversation #:conversation_number", ['customer' => $this->customer->getFullName(true), 'conversation_number' => $conversation_number]);
|
||||
}
|
||||
|
8
resources/views/emails/user/email_reply_error.blade.php
Normal file
8
resources/views/emails/user/email_reply_error.blade.php
Normal file
@ -0,0 +1,8 @@
|
||||
@extends('emails/user/layouts/system')
|
||||
|
||||
@section('content')
|
||||
<div style="color:#2a3b47;font:500 20px/26px 'Helvetica Neue',Helvetica,Arial,sans-serif">{{ __("Your email update couldn't be processed") }}</div>
|
||||
<p style="border-left: 3px solid #e52f28; padding: 0 0 0 10px; color:#72808e;font:400 16px/26px 'Helvetica Neue',Helvetica,Arial,sans-serif;">
|
||||
{{ __("If you are trying to update a conversation, remember you must respond from the same email address that's on your account. To send your update, please try again and send from your account email address (the email you login with).") }}
|
||||
</p>
|
||||
@endsection
|
@ -1 +1 @@
|
||||
@if ($thread->created_by_user->id == $user->id){{ __("you") }}@else{{ $thread->created_by_user->getFullName(true) }}@endif
|
||||
@if ($thread->created_by_user_id == $user->id){{ __("you") }}@else{{ $thread->created_by_user->getFullName(true) }}@endif
|
Loading…
Reference in New Issue
Block a user