mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-30 21:21:09 -04:00 
			
		
		
		
	connect mail sender with api
This commit is contained in:
		| @ -223,204 +223,6 @@ class EnvironmentManager | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|     * Save the mail content to the .env file. | ||||
|     * | ||||
|     * @param Request $request | ||||
|     * @return array | ||||
|     */ | ||||
|     public function saveMailVariables(MailEnvironmentRequest $request) | ||||
|     { | ||||
|         $mailData = $this->getMailData($request); | ||||
|  | ||||
|         try { | ||||
|             file_put_contents($this->envPath, str_replace( | ||||
|                 $mailData['old_mail_data'], | ||||
|                 $mailData['new_mail_data'], | ||||
|                 file_get_contents($this->envPath) | ||||
|             )); | ||||
|  | ||||
|             if ($mailData['extra_old_mail_data']) { | ||||
|                 file_put_contents($this->envPath, str_replace( | ||||
|                     $mailData['extra_old_mail_data'], | ||||
|                     $mailData['extra_mail_data'], | ||||
|                     file_get_contents($this->envPath) | ||||
|                 )); | ||||
|             } else { | ||||
|                 file_put_contents( | ||||
|                     $this->envPath, | ||||
|                     "\n".$mailData['extra_mail_data'], | ||||
|                     FILE_APPEND | ||||
|                 ); | ||||
|             } | ||||
|         } catch (Exception $e) { | ||||
|             return [ | ||||
|                 'error' => 'mail_variables_save_error', | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             'success' => 'mail_variables_save_successfully', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     private function getMailData($request) | ||||
|     { | ||||
|         $mailFromCredential = ""; | ||||
|         $extraMailData = ""; | ||||
|         $extraOldMailData = ""; | ||||
|         $oldMailData = ""; | ||||
|         $newMailData = ""; | ||||
|  | ||||
|         if (env('MAIL_FROM_ADDRESS') !== null && env('MAIL_FROM_NAME') !== null) { | ||||
|             $mailFromCredential = | ||||
|                 'MAIL_FROM_ADDRESS='.config('mail.from.address')."\n". | ||||
|                 'MAIL_FROM_NAME="'.config('mail.from.name')."\"\n\n"; | ||||
|         } | ||||
|  | ||||
|         switch ($request->mail_driver) { | ||||
|             case 'smtp': | ||||
|  | ||||
|                 $oldMailData = | ||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". | ||||
|                     'MAIL_HOST='.config('mail.host')."\n". | ||||
|                     'MAIL_PORT='.config('mail.port')."\n". | ||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|                     $mailFromCredential; | ||||
|  | ||||
|                 $newMailData = | ||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". | ||||
|                     'MAIL_HOST='.$request->mail_host."\n". | ||||
|                     'MAIL_PORT='.$request->mail_port."\n". | ||||
|                     'MAIL_USERNAME='.$request->mail_username."\n". | ||||
|                     'MAIL_PASSWORD='.$request->mail_password."\n". | ||||
|                     'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". | ||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; | ||||
|  | ||||
|                 break; | ||||
|  | ||||
|             case 'mailgun': | ||||
|                 $oldMailData = | ||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". | ||||
|                     'MAIL_HOST='.config('mail.host')."\n". | ||||
|                     'MAIL_PORT='.config('mail.port')."\n". | ||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|                     $mailFromCredential; | ||||
|  | ||||
|                 $newMailData = | ||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". | ||||
|                     'MAIL_HOST='.$request->mail_host."\n". | ||||
|                     'MAIL_PORT='.$request->mail_port."\n". | ||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|                     'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". | ||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; | ||||
|  | ||||
|                 $extraMailData = | ||||
|                     'MAILGUN_DOMAIN='.$request->mail_mailgun_domain."\n". | ||||
|                     'MAILGUN_SECRET='.$request->mail_mailgun_secret."\n". | ||||
|                     'MAILGUN_ENDPOINT='.$request->mail_mailgun_endpoint."\n"; | ||||
|  | ||||
|                 if (env('MAILGUN_DOMAIN') !== null && env('MAILGUN_SECRET') !== null && env('MAILGUN_ENDPOINT') !== null) { | ||||
|                     $extraOldMailData = | ||||
|                         'MAILGUN_DOMAIN='.config('services.mailgun.domain')."\n". | ||||
|                         'MAILGUN_SECRET='.config('services.mailgun.secret')."\n". | ||||
|                         'MAILGUN_ENDPOINT='.config('services.mailgun.endpoint')."\n"; | ||||
|                 } | ||||
|  | ||||
|                 break; | ||||
|  | ||||
|             case 'ses': | ||||
|                 $oldMailData = | ||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". | ||||
|                     'MAIL_HOST='.config('mail.host')."\n". | ||||
|                     'MAIL_PORT='.config('mail.port')."\n". | ||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|                     $mailFromCredential; | ||||
|  | ||||
|                 $newMailData = | ||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". | ||||
|                     'MAIL_HOST='.$request->mail_host."\n". | ||||
|                     'MAIL_PORT='.$request->mail_port."\n". | ||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|                     'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". | ||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; | ||||
|  | ||||
|                 $extraMailData = | ||||
|                     'SES_KEY='.$request->mail_ses_key."\n". | ||||
|                     'SES_SECRET='.$request->mail_ses_secret."\n"; | ||||
|  | ||||
|                 if (env('SES_KEY') !== null && env('SES_SECRET') !== null) { | ||||
|                     $extraOldMailData = | ||||
|                         'SES_KEY='.config('services.ses.key')."\n". | ||||
|                         'SES_SECRET='.config('services.ses.secret')."\n"; | ||||
|                 } | ||||
|  | ||||
|                 break; | ||||
|  | ||||
|             case 'mail': | ||||
|                 $oldMailData = | ||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". | ||||
|                     'MAIL_HOST='.config('mail.host')."\n". | ||||
|                     'MAIL_PORT='.config('mail.port')."\n". | ||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|                     $mailFromCredential; | ||||
|  | ||||
|                 $newMailData = | ||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". | ||||
|                     'MAIL_HOST='.config('mail.host')."\n". | ||||
|                     'MAIL_PORT='.config('mail.port')."\n". | ||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; | ||||
|  | ||||
|                 break; | ||||
|  | ||||
|             case 'sendmail': | ||||
|                 $oldMailData = | ||||
|                     'MAIL_DRIVER='.config('mail.driver')."\n". | ||||
|                     'MAIL_HOST='.config('mail.host')."\n". | ||||
|                     'MAIL_PORT='.config('mail.port')."\n". | ||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|                     $mailFromCredential; | ||||
|  | ||||
|                 $newMailData = | ||||
|                     'MAIL_DRIVER='.$request->mail_driver."\n". | ||||
|                     'MAIL_HOST='.config('mail.host')."\n". | ||||
|                     'MAIL_PORT='.config('mail.port')."\n". | ||||
|                     'MAIL_USERNAME='.config('mail.username')."\n". | ||||
|                     'MAIL_PASSWORD='.config('mail.password')."\n". | ||||
|                     'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". | ||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; | ||||
|  | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             'old_mail_data' => $oldMailData, | ||||
|             'new_mail_data' => $newMailData, | ||||
|             'extra_mail_data' => $extraMailData, | ||||
|             'extra_old_mail_data' => $extraOldMailData, | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Save the disk content to the .env file. | ||||
|      * | ||||
|  | ||||
		Reference in New Issue
	
	Block a user