Failed sending mail in Lumen - lumen

i'm trying to make a custom email configuration in the service provider, and when trying to send an email i got this error Argument 1 passed to Illuminate\Mail\MailManager::getConfig() must be of the type string, null given (src/Illuminate/Mail/MailManager.php on line 108 )

When posting a question like this, you'll get much better responses if you supply more context, for example:
The line of code that is calling getConfig() and the lines that define relevant variables just before that.
According to the documentation, it looks like you need to set the following in your project's .env file:
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hello#example.com
MAIL_FROM_NAME="Example app"
Some ideas on the road to fixing it:
I would check everywhere for typos and spelling errors.
Clear the config: php artisan config:clear
Does every environment variable match the server your trying to send through? Note that if you're using a free SMTP server like Gmail you'll need to make many adjustments to your account before you can send... Probably use something like SendGrid if you don't know how to set this up yourself.
I would make sure that you're able to use telnet mail.example.com 587 and get a HELO from the SMTP server.
Try whatever other steps you can think of for troubleshooting then update your post with more complete information.
Good luck.

Related

Mail stay in queue when i use Sendgrid in symfony6

I have set my Sendgrid single sender and validate it ( status = verified).
I use SMTP, create my key that i paste in my code (.env file of my app):
MAILER_DSN=sendgrid+smtp://#default
Then i try to test integration in Sendgrid by clicking on button and refresh my localhost/ page (of course the controller's route is "/" and it contains the code using mailer to send a mail as explain in mailer documentation).
On my vue i don't have error code but mail stay in queue status...
Here the screenshot taken of the profiler:
Can someone tell me why my mail stay queued?
Of course the From email address is mine ( the verified one) and the To is anotherone of mine.
Maybe i have to configure something in my outlook mail (the From one) ?
Sendgrid never match the verification, it stay in checking status until message :
Hmm, we haven't seen your email yet.
Please check your code, run it again, then click "Retry".
Thanks for reply,
Regards,
In your question you said that your MAILER_DSN environment variable is set to:
MAILER_DSN=sendgrid+smtp://#default
That is missing your API Key though. You need to create an API key in the SendGrid dashboard and then add the API key to the MAILER_DSN variable, between the // and the #default like this:
MAILER_DSN=sendgrid+smtp://API_KEY#default
One other thing, ensure that you have installed the SendGrid transport with this command:
composer require symfony/sendgrid-mailer
Yes, thanks you a lot for reply.
Of course all was set as you notify me.
I now have fix my issue, in fact the problem for me with the mail that remains in queued is that the messenger was installed so in asynchronous by default.
I had to add the option message_bus: false in my config/packages/mailer.yaml file not to have the asynchronous option used.
Hopefully this is useful for some people.
add the option message_bus: false in my config/packages/mailer.yaml:
framework:
mailer:
dsn: '%env(MAILER_DSN)%'
message_bus: false

Links have random characters prepended in email

I am using the current link in my email.
*|baseUrl|*/verifyEmail?token=*|token|*
This however causes one or two people to get strange links from the email and get not found, usually based on some random email providers. E.g. - if I use a 10 minute mail (10minutemail.com), I get the following:
https://10minutemail.com/10MinuteMail/www.mywebsite.com/verifyEmail?token=b32fee82da59e7b4085269faca35ec7025122876
Correct link: www.mywebsite.com/verifyEmail?token=b32fee82da59e7b4085269faca35ec7025122876
Assuming this is due to baseUrl? Am I doing something fundamentally wrong when setting up my email link?
You need to include http:// or https:// with your baseUrl. Otherwise the email client may prepend a default base address instead of 'just' the missing protocol, especially if it is a webmail client.

IMAP "Invalid Credentials" via GMail XOAUTH

I'm trying to get into the IMAP server with OAuth, using the PHP Sample Code provided by Google which uses the Zend Imap class but I am failing to authenticate. Zend is giving me the error:
Zend_Mail_Storage_Exception [ Error ]: cannot select INBOX, is this a valid transport?
Annoyingly this is a rather confusing error message, for what is essentially "Invalid Credentials". How did I know that? By debugging the actual commands being send to the IMAP socket I see this:
string(44) "NO Invalid credentials ey9if1544983wid.142
"
I have tried with telnet and a Ruby gmail_xoauth gem which suggests it is not a code issue, but something else.
Looking at the most basic level of all this, I am getting commands like this:
TAG1 AUTHENTICATE XOAUTH R0VUIGh0dHBzOi8vbWFpbC5nb29nbGUuY29tL21h......etc
This is where I get NO Invalid credentials then:
TAG2 SELECT "INBOX"
This returns BAD Unknown command and kicks me out.
I have tried searching around for people having the same problem but I find only questions and no answers. There are a few similar StackOverflow questions:
One post shows somebody having the exact same problem in Python.
This post shows somebody trying to be awkward and do it with OAuth 2, with no report of success.
There is a thread on the GMail Google Group that suggests an "Invalid Credentials" error can be resolved by going to https://accounts.google.com/DisplayUnlockCaptcha for GMail accounts and https://www.google.com/a/[YOURDOMAIN.COM]/UnlockCaptcha if you are using Google Apps, but the latter just said that my username and password were wrong when they clearly were not. Using this https://accounts.google.com/DisplayUnlockCaptcha worked fine - even though my account is a hosted App, not plain old GMail - however I still get the same errors when trying to log back in with the PHP sample code provided by Google.
I've tried with various hosted Google App accounts and a plain GMail account. I've tried switching the IMAP server from imap.gmail.com to imap.googlemail.com, nothing makes any difference.
/**
* Make the IMAP connection and send the auth request
*/
$imap = new Zend_Mail_Protocol_Imap('imap.googlemail.com', '993', true);
$authenticateParams = array('XOAUTH', $initClientRequestEncoded);
$imap->requestAndResponse('AUTHENTICATE', $authenticateParams);
/**
* Print the INBOX message count and the subject of all messages
* in the INBOX
*/
$storage = new Zend_Mail_Storage_Imap($imap);
echo '<h1>Total messages: ' . $storage->countMessages() . "</h1>\n";
For those with an interest, this is the specific PHP code that sets up the connection, all XOauth is handled by Google's PHP in the same file but I skipped it.
I had this exact same error, and eventually realised I was using the wrong scope when requesting the OAuth permissions.
You need to have...
scope=https://mail.google.com/
access_type=offline
And also IMAP enabled in your Gmail account obviously. All seems good now.
One problem you may have is that the third parameter of Zend_Mail_Protocol_Imap('imap.googlemail.com', '993', true); should not be true. It should be a string, as either "SSL" or "TLS". I believe you want "SSL" if going over port 993. It's only a boolean when it is FALSE.
Try replacing that first line with this:
$imap = new Zend_Mail_Protocol_Imap('imap.googlemail.com', '993', 'SSL');
When i had this same error message, it was because
$options['consumerSecret'] = $THREE_LEGGED_CONSUMER_SECRET_HMAC;
I was doing that in a function and variable $THREE_LEGGED... wasn't in the scope. Pretty stupid and i'm sure that you'd have spotted that but just in case somebody new is reading that.

email not proper in rails 3

I've same problem like here. But still not able to solve it.
I've followed steps from here. but doing so doesn't sends mail.
The log file says: Mail is sent. but at the other side mail is not received.
Any ideas why?
Check your SMTP settings and make sure you have defined the right settings for your e-mail host. If you are using a sender e-mail other than Gmail then your settings will be different to the ones used in the Railscast.
The file to check is here: config/initializers/setup_mail.rb.
Edit: It still may be possible that the settings you used in jsp may not match perfectly with the 'phrasing' that Rails expects in the setup_mail.rb file. I have frequently come up against this problem where a slight difference in what SMTP settings you mention / don't mention / how they are worded will determine whether the e-mails send/receive or not.
If your logs show the e-mail is sending to a valid e-mail address (and you are not receiving those e-mails in your inbox or spam filter) then the problem, as far as I know, is most likely to be your SMTP. My advice is to check online for the Rails-specific SMTP settings for your e-mail provider, or in the case that you cannot find them, try different combinations until you find the correct one.
Okay the problem is solved. Problem was my file corresponding to action was not at proper place. Here is quick view on how to do it:
Add following to actionmailer:-
def send_mail
attachments['1.pdf'] = File.read('c:/1.pdf')
mail(:to => "harsh#xyz.com", :subject => "xyz", :from=>"harsh#xyz.com")
mail.deliver
end
Notes:- Make sure that the smtp settings are correct and the file corresponding to the action (In this example send_mail.rhtml) is present under appropriate folder.

aliases (sendmail) to redirect emails

I have read that "aliases" (etc/aliases) can be used to redirect an email to an external email address (or piping it to a script etc.)
It should normally work by putting this command in the "aliases" file:
support: myemail#hotmail.com
Afterwards you have to use the newaliases-command and thats it.
But unfortunately after doing these two steps it doesn't work at all: I don't receive any forwarded email. And there is no error message in the log files as far as I can see.
It would be great if anyone could help me to solve this problem.
Jennifer
Sorry, sendmail wasn't properly configured.
This was the problem... :-/