fwrite() ssl broken pipe in swiftmailer while sending email - laravel-5

I am using Laravel 5.2. I am using Mail queue for sending email. Following is email queue syntax.
$mailArr = array();
$mailArr['subject'] = 'testing mail';
$mail_body = 'testing mail';
$mailArr['description'] = $mail_body;
Mail::to($email)->queue(new CustomMail($mailArr));
If I use "send" instead of "queue" then successfully receiving email.
Queue emails are going in Job table and attempting 3 times and then it is going in failed_jobs table.
In failed_jobs table, I am getting error ErrorException: fwrite(): SSL: Broken pipe in vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:231
I am processing queue with dispatcher and supervisor.
If I manually hit php artisan queue:work even then email is going but automatically with schedule:run written in cron job, is not working.
So any suggestions please what could be the reason?

This response is received when the remote connection closes without informing your server as to why. Usually due to a restriction, such as mail size.
Try using an alternative mailer, such as Mailtrap for example and try the queue again to see if the error response is different.
It is likely you had a plumbing issue; a huge email in your queue prior to your other emails, that’s why sends were processing fine but your queue wasn’t.

Related

Python FlasK Mail. 4.3.2 Concurrent connections limit exceeded

I am trying to send mail using python flask_mail module.
The email I am using is hosted/created by godady outlook. It is able to send email successfully. However, when there are multiple users that trigger sending of email functions, I get the following error:
raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (432, b'4.3.2 Concurrent connections limit exceeded. Visit https://aka.ms/concurrent_sending for more information. [Hostname=H...apcprd04.prod.outlook.com]')
How do I go about solving this issue? I was thinking if this is server imposed limit, I have to somehow queue the email sending function call, and send email one by one.

Laravel SMTP sending email by queue receiving empty response

I'm running Laravel 6.20.0 and I'm experiencing the following error since yesterday when my queue worker is trying to send an email:
Swift_TransportException: Expected response code 250 but got an empty response in public_html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:448
I've tried requeuing my emails several times now since yesterday, but I keep on receiving the same error when it attempts to send. This worked flawlessly before for almost a year, so I'm a bit confused what is causing this issue. I haven't changed any credentials nor changed any code or configuration recently.
My mail settings are as follows:
MAIL_DRIVER=smtp
MAIL_HOST="smtp-relay.gmail.com"
MAIL_PORT=587
MAIL_USERNAME="my#user.name"
MAIL_PASSWORD="myapppassword"
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="my#from.address"
MAIL_FROM_NAME="My Name"
I've doubled checked in my Google Admin that both the IPv4 address as well as the IPv6 address of my server are whitelisted and the SMTP relay service is enabled. I also created a new App password within my Google account to see if that would fix the problem - but no luck there.
I've also cleared the config cache (and have tried php artisan config:cache) and tried restarting supervisor which runs the worker running the task for the email queue. I've also tried requeueing the emails one by one in case I triggered some kind of throttling, but to no avail. By no means is my website sending many emails, about a 100 a month, well within the limits posed by my email account. (And I currently got <10 stuck in queue.)
As a last resort I turned off SMTP verification and TLS encryption in the Google Admin, so the only requirement for using the SMTP was having the IP address whitelisted (which it is). But this didn't work either, so I've switched SMTP verification and TLS encryption back on again as a requirement.
Finally; I ran a composer update, but that didn't fix the problem either.
I've found some other older threads on Stackoverflow with a similar problem, but I had already tried all offered solutions as described above.
What am I missing?
i think you need change mail port to 25 like this :
MAIL_PORT=25
Just faced same issue.
In my case SMTP sending worked when I tried to send an email without queues.
But when I tried to send same email with same config using queue, I got error that looks like:
[2021-02-15 12:43:24] local.ERROR: Expected response code 250 but got an empty response {"exception":"[object] (Swift_TransportException(code: 0): Expected response code 250 but got an empty response at /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:448)
[stacktrace]
#0 /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(345): Swift_Transport_AbstractSmtpTransport->assertResponseCode('', Array)
#1 /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(305): Swift_Transport_AbstractSmtpTransport->executeCommand('HELO [127.0.0.1...', Array, Array, false, NULL)
#2 /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(368): Swift_Transport_EsmtpTransport->executeCommand('HELO [127.0.0.1...', Array)
#3 /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(341): Swift_Transport_AbstractSmtpTransport->doHeloCommand()
#4 /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(148): Swift_Transport_EsmtpTransport->doHeloCommand()
After long research I've found that issue is related with HELO command itself.
As you can clearly see in the log, for some reason (probably server hostname) there is 127.0.0.1 IP address, which Google is blocking.
How I resolved that:
So to resolve that, I've added one little line in my artisan file:
$_SERVER['SERVER_NAME'] = 'mydomain.com';
So my artisan file looks like this now:
#!/usr/bin/env php
<?php
$_SERVER['SERVER_NAME'] = 'mydomain.com';
define('LARAVEL_START', microtime(true));
...
Spoke with Google Workspace rep
As a temporary solution they asked to use
smtp.gmail.com instead of smtp-relay.gmail.com
Worked on 2 of our projects.
P.S. The limit is 130 emails per account on Workspace (former Gsuite)
for example if you have 5 users, 5x130=650
What the rep said haha :)

There is no active transaction when multiple AJAX requests from same user

I have a rather embarrassing problem.
In a conversation system, when the user sends a message, an AJAX request is sent and then a PDO transaction is created to make multiple INSERT and UPDATE.
To test, I spammed the sending of messages, resulting in multiple AJAX requests being sent in parallel. Out of ten messages sent "at the same time", several transactions will bug, the Laravel error handler sends me "There is no active transaction".
Is it a PDO configuration problem? I put DB::beginTransaction above a try catch. Apparently, the bug is in the DB::commit, which detects when there is no more transaction in progress.
Is it the fact that it is my "user session" that sends AJAX requests that cancels a PDO transaction on another request than the current one?
I use Laravel 5.8.19 and CockroachDB 19.1.1.1.
Thanks for the help.

How to try queue again in Laravel 5.2?

I am trying to send SMS using my laravel project for that purpose I wrote function in MessageController named sendSms. I am pushing message data to a queue named SendScheduledSms and handler as follows.
public function handle()
{
$sentsms = App::make('App\Http\Controllers\MessageController')->sendSms($this->post_data);
}
Sending SMS works properly. $sentsms is the status of sent SMS. There are two values for $status, success and fail. I want to re-try sending same SMS if status is fail. How can I do that?
Now when sendSms executed, it deletes the queue.
I am using database queue.
Can anyone help?
In order to trigger Laravel Queue's native retry functionality, your Job handle method will need to throw an error at some point.
if ($sentsms == 'fail') {
throw new Exception('SMS failed to send.');
}
If you have a failed_jobs table set up the job should be moved there by Laravel.
See the documentation on Retrying failed jobs.
In your console schedule method set the --tries flag to have Laravel automatically rerun failed jobs.
$schedule->command("queue:work --tries=3")->everyMinute();

codeigniter mail sending error 451

Can any one tell me why I'm getting this error with codeigniter when it comes to sending mail.
some time it work fine some times i get this error
451 Please try again later
The following SMTP error was encountered: 451 Please try again later
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Are you sure your SMTP server is working fine at the time you get this error? If it works sometimes, then that means that your configuration is probably fine. I'd deploy the code of a test server online and then run your code to see if its really a configuration problem or maybe a problem with the SMTP host that you're trying to send the mail through.

Resources