diff --git a/app/Console/Commands/Flex/FlexStructureCommand.php b/app/Console/Commands/Flex/FlexStructureCommand.php
index 0509341c4..418d3804a 100644
--- a/app/Console/Commands/Flex/FlexStructureCommand.php
+++ b/app/Console/Commands/Flex/FlexStructureCommand.php
@@ -16,7 +16,7 @@ use Commands\Library\CommandHelper;
//Models
use App\Models\Flex\FlexStructure;
use App\Models\Mail\SentMail;
-use App\Models\Mail\EveMail;
+use App\Models\Jobs\JobSendEveMail;
class FlexStructureCommand extends Command
{
@@ -93,7 +93,7 @@ class FlexStructureCommand extends Command
$body += "Warped Intentions Leadership
";
//Dispatch the mail job
- $mail = new EveMail;
+ $mail = new JobSendEveMail;
$mail->sender = $config['primary'];
$mail->subject = "Warped Intentions Flex Structures Payment Due for " . $today->englishMonth;
$mail->body = $body;
diff --git a/app/Console/Commands/Moons/MoonMailer.php b/app/Console/Commands/Moons/MoonMailer.php
index 26e92088b..31a5c4b96 100644
--- a/app/Console/Commands/Moons/MoonMailer.php
+++ b/app/Console/Commands/Moons/MoonMailer.php
@@ -20,7 +20,6 @@ use App\Models\Moon\Moon;
use App\Models\MoonRent\MoonRental;
use App\Models\Jobs\JobSendEveMail;
use App\Models\Mail\SentMail;
-use App\Models\Mail\EveMail;
class MoonMailerCommand extends Command
{
@@ -113,8 +112,6 @@ class MoonMailerCommand extends Command
//Increment the delay for the mail to not hit rate limits
$delay += 30;
- $this->SendMail($mail);
-
//Update the moon as not being paid for the next month?
foreach($rentals as $rental) {
$previous = new Carbon($rental->Paid_Until);
diff --git a/app/Http/Controllers/Contracts/ContractAdminController.php b/app/Http/Controllers/Contracts/ContractAdminController.php
index 7feaada47..619c4c380 100644
--- a/app/Http/Controllers/Contracts/ContractAdminController.php
+++ b/app/Http/Controllers/Contracts/ContractAdminController.php
@@ -19,7 +19,6 @@ use App\Models\User\UserPermission;
use App\Models\Contracts\Contract;
use App\Models\Contracts\Bid;
use App\Models\Contracts\AcceptedBid;
-use App\Models\Mail\EveMail;
use App\Models\Jobs\JobSendEveMail;
class ContractAdminController extends Controller
@@ -137,7 +136,6 @@ class ContractAdminController extends Controller
]);
//Declare class variables
- $mail = new Mail;
$tries = 1;
//Get the esi config
@@ -156,7 +154,7 @@ class ContractAdminController extends Controller
$body .= 'Sincerely,
Spatial Forces Contracting Department';
//Setup the mail job
- $mail = new EveMail;
+ $mail = new JobSendEveMail;
$mail->subject = $subject;
$mail->recipient_type = 'character';
$mail->recipient = $bid['character_id'];
@@ -195,7 +193,7 @@ class ContractAdminController extends Controller
//Cycle through the users with the correct permission and send a mail to go out with the queue system.
foreach($users as $user) {
- $mail = new EveMail;
+ $mail = new JobSendEveMail;
$mail->sender = $config['primary'];
$mail->subject = 'New Alliance Contract Available';
$mail->recipient = $user['character_id'];
diff --git a/app/Http/Controllers/Logistics/StructureRequestController.php b/app/Http/Controllers/Logistics/StructureRequestController.php
index 8e1a405b8..a308104bc 100644
--- a/app/Http/Controllers/Logistics/StructureRequestController.php
+++ b/app/Http/Controllers/Logistics/StructureRequestController.php
@@ -18,7 +18,6 @@ use App\Library\Lookups\LookupHelper;
use App\Models\Logistics\AnchorStructure;
use App\Models\Mail\SentMail;
use App\Models\Jobs\JobSendEveMail;
-use App\Models\Mail\EveMail;
class StructureRequestController extends Controller
{
diff --git a/app/Jobs/ProcessSendEveMailJob.php b/app/Jobs/ProcessSendEveMailJob.php
index cd974cdca..2566ce37a 100644
--- a/app/Jobs/ProcessSendEveMailJob.php
+++ b/app/Jobs/ProcessSendEveMailJob.php
@@ -13,11 +13,12 @@ use Log;
//Library
use App\Library\Esi\Esi;
use Seat\Eseye\Exceptions\RequestFailedException;
+use Seat\Eseye\Cache\NullCache;
+use Seat\Eseye\Configuration;
//Models
use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken;
-use App\Models\Mail\EveMail;
use App\Models\Jobs\JobStatus;
use App\Models\Mail\SentMail;
use App\Models\Jobs\JobSendEveMail;
@@ -78,7 +79,7 @@ class ProcessSendEveMailJob implements ShouldQueue
$config = config('esi');
//Retrieve the token for main character to send mails from
- $token = EsiToken::where(['character_id'=> $this->sender])->first();
+ $token = $esiHelper->GetRefreshToken($config['primary']);
//Create the ESI authentication container
$esi = $esiHelper->SetupEsiAuthentication($token);
diff --git a/app/Library/Esi/Esi.php b/app/Library/Esi/Esi.php
index b68ca24a9..d432a07e7 100644
--- a/app/Library/Esi/Esi.php
+++ b/app/Library/Esi/Esi.php
@@ -10,7 +10,6 @@ use Carbon\Carbon;
use App\Models\Esi\EsiToken;
use App\Models\Esi\EsiScope;
use App\Models\Jobs\JobSendEveMail;
-use App\Models\Mail\EveMail;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
@@ -43,14 +42,14 @@ class Esi {
$check = EsiScope::where(['character_id' => $charId, 'scope' => $scope])->count();
if($check == 0) {
//Compose a mail to send to the user if the scope is not found
- $mail = new EveMail;
+ $mail = new JobSendEveMail;
$mail->sender = $config['primary'];
$mail->subject = 'W4RP Services - Incorrect ESI Scope';
$mail->body = "Please register on https://services.w4rp.space with the scope: " . $scope;
$mail->recipient = (int)$charId;
$mail->recipient_type = 'character';
- ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds(5));
+ ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(5);
return false;
}
diff --git a/app/Library/Finances/Helper/FinanceHelper.php b/app/Library/Finances/Helper/FinanceHelper.php
index c8befec6d..333c988f4 100644
--- a/app/Library/Finances/Helper/FinanceHelper.php
+++ b/app/Library/Finances/Helper/FinanceHelper.php
@@ -17,7 +17,6 @@ use App\Jobs\ProcessSendEveMailJob;
//Models
use App\Models\Esi\EsiToken;
use App\Models\Esi\EsiScope;
-use App\Models\Mail\EveMail;
//Library
use App\Library\Esi\Esi;
diff --git a/app/Library/Mail/Helper/EveMailHelper.php b/app/Library/Mail/Helper/EveMailHelper.php
new file mode 100644
index 000000000..b910b92a4
--- /dev/null
+++ b/app/Library/Mail/Helper/EveMailHelper.php
@@ -0,0 +1,73 @@
+HaveEsiScope($sender, 'esi-mail.send_mail.v1')) {
+ Log::critical('Could not find correct scope for the token for the mailer.');
+ return null;
+ }
+
+ //Retrieve token from from the database for the sender
+ $token = $esiHelper->GetRefreshToken($sender);
+
+ //Create the ESI authentication container
+ $esi = $esiHelper->SetupEsiAuthentication($token);
+
+ //Set caching to null
+ $configuration = Configuration::getInstance();
+ $configuration->cache = NullCache::class;
+
+ //Attempt to send the mail
+ try {
+ $esi->setBody([
+ 'approved_cost' => 100,
+ 'body' => $this->body,
+ 'recipients' => [[
+ 'recipient_id' => $this->recipient,
+ 'recipient_type' => $this->recipient_type,
+ ]],
+ 'subject' => $this->subject,
+ ])->invoke('post', '/characters/{character_id}/mail/', [
+ 'character_id'=> $this->sender,
+ ]);
+ } catch(RequestFailedException $e) {
+ Log::warning($e);
+ return null;
+ }
+ }
+}
\ No newline at end of file