mail sending issue in laravel 5.4 - email

I am trying to send an email using laravel 5.4. here is my .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
here is my HomeController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Mail;
use App\Mail\MyTestMail;
class HomeController extends Controller
{
/**
* Send My Test Mail Example
*
* #return void
*/
public function myTestMail()
{
//echo 'hello';
$myEmail = 'example#gmail.com';
Mail::to($myEmail)->send(new MyTestMail());
dd("Mail Send Successfully");
}
}
But i got an error like
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "535", with message "535-5.7.8
Username and Password not accepted. Learn more at 535 5.7.8
https://support.google.com/mail/?p=BadCredentials r67sm38867592pfb.125
- gsmtp "
at Swift_Transport_AbstractSmtpTransport->_assertResponseCode('535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials r67sm38867592pfb.125 - gsmtp ', array(250)) in AbstractSmtpTransport.php line 281
at Swift_Transport_AbstractSmtpTransport->executeCommand('RSET ', array(250), array()) in EsmtpTransport.php line 270
at Swift_Transport_EsmtpTransport->executeCommand('RSET ', array(250)) in XOAuth2Authenticator.php line 55
at Swift_Transport_Esmtp_Auth_XOAuth2Authenticator->authenticate(object(Swift_SmtpTransport), 'username#gmail.com', 'password') in AuthHandler.php line 176
at Swift_Transport_Esmtp_AuthHandler->afterEhlo(object(Swift_SmtpTransport)) in EsmtpTransport.php line 332
Then i changed to my .env file to
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username2#gmail.com
MAIL_PASSWORD=password2
MAIL_ENCRYPTION=tls
then i restart apache2.But still the same error with previous username and password.i don't know why this happens?please help me.

Google now doesn't accept login from less secure apps
You need to authorise the external application use of Gmail.
Follow the next steps and authorise to make it:
First, go to your Google Account Management page
Under the Security options, click Edit link of Authorising
applications & sites
or
You can allow less secure apps from your settings in Gmail, go to:
https://www.google.com/settings/security/lesssecureapps
and set 'Access for less secure apps' to "Enabled"
Hope it helps you.

Related

AdonisJS : Can't send email via #adonisjs/mail

I use adonis js version 4.1.0 and #adonisjs/mail version ^3.0.10. I'm not sure why. But I'm sure my email and password are correct which previously email can be used normally. Please help me. Thank for your solution. I got this error when I send email ExceptionHandler Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials 136-20020a62188e000000b0050dc7628158sm4991712pfy.50 - gsmtp
my .env like this
MAIL_USERNAME=test#gmail.com
MAIL_PASSWORD=testpw
SMTP_HOST=smtp.gmail.com
and I using
const data = `<div>Testing</div>`;
await Mail.raw(data, (message) => {
message.to(getEmail.email);
message
.from(`${Env.get("MAIL_USERNAME")}`)
.subject("Test Email Sending");
});
In my config/mail.js
Due to a change in Google email policy, you can't send mail using your password.
enable 2-step verification click
create App passwords for your mail click
replace your .env MAIL_PASSWORD with generated 16 digit app password.

Getting "Client was not authenticated to send anonymous mail during MAIL FROM" error from Exchange SMTP using Rust lettre library

I am writing a Rust application that will send email through an Exchange server with SMTP functionality enabled. According to Microsoft's webpage, the settings that are required are:
Server address smtp.office365.com
Port 587
StartTLS Enabled
Credentials for mail account login
These are corroborated by the POP/IMAP settings of the webmail service.
Here is my code (with some censoring):
extern crate lettre;
use self::lettre::email::EmailBuilder;
use self::lettre::transport::smtp::{SecurityLevel, SmtpTransportBuilder, SUBMISSION_PORT};
use self::lettre::transport::smtp::authentication::Mechanism;
use self::lettre::transport::EmailTransport;
pub fn send_mail() {
let email = EmailBuilder::new()
.from("my email")
.to("destination email")
.body("testing")
.subject("testing")
.build()
.unwrap();
// Connect to SMTP server
let mut transport = SmtpTransportBuilder::new(("smtp.office365.com", SUBMISSION_PORT))
.expect("Failed to create email transport")
.encrypt()
.smtp_utf8(true)
.credentials("my email", "my password")
.authentication_mechanism(Mechanism::Login)
.build();
println!("Mail transport built");
println!("{:?}", transport.send(email.clone()));
}
When I compile and run the code,it gives me this error:
Err(Permanent(Response { code: Code { severity:
PermanentNegativeCompletion, category: Unspecified3, detail: 0 },
message: ["5.7.57 SMTP; Client was not authenticated to send anonymous
mail during MAIL FROM [SYXPR01CA0106.ausprd01.prod.outlook.com]"] }))
Why is this happening?
The closest I've come in my research is an issue on GitHub in relation to the lettre library not supporting the Login authentication mechanism (which Office 365 uses); however, the codebase was updated to support Login and I am using the master branch directly from GitHub so theoretically my application should support the Login mechanism.
Edit: Forgot to mention that I attempted an EHLO to the server, but it returned a (Client:(Connection closed)) error.
I used telnet and openssl to try connecting directly to my SMTP server, where I found that AUTH LOGIN requires 3 commands; one to send the AUTH LOGIN code, one to send the username and another to send the password. I found that the lettre library implements all its AUTH commands as single commands, so this wasn't working with the server. I downloaded the source code for the library, changed the send function to do the three separate commands, recompiled my code and everything worked fine :)
My addition to the lettre code:
if (accepted_mechanisms[0] == Mechanism::Login) &&
(accepted_mechanisms.capacity() == 1) {
try_smtp!(self.client.command("AUTH LOGIN"), self);
try_smtp!(self.client.command(base64::encode_config(
&username.as_bytes(),
base64::STANDARD).as_str()), self);
try_smtp!(self.client.command(base64::encode_config(
&password.as_bytes(),
base64::STANDARD).as_str()), self);

How to send email with Jenkins and an parameter address?

I'm using Jenkins and I would like to send an email after finished job. The problem I have is that I want to use the username defined before into a parameter in the configuration. I try to use then ${username} but i doesn't work. This is the error I get:
Sending e-mails to: ${username}#email.es
ERROR: Invalid Addresses
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.1 <${username}#email.es>... User unknown
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1835)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1098)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at hudson.tasks.MailSender.run(MailSender.java:126)
at hudson.tasks.MailSender.execute(MailSender.java:101)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.cleanUp(MavenModuleSetBuild.java:1064)
at hudson.model.Run.execute(Run.java:1764)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531)
at hudson.model.ResourceController.execute(ResourceController.java:89)
at hudson.model.Executor.run(Executor.java:240)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.1 <${username}#email.es>... User unknown
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1686)
... 10 more
It is not taking the value of the parameter. Is thera any plugin or way to do this ?
Thanks for your help.
instead of ${username} - use $username
Ex: $username#$domain.com
Here, username and domain are two parameters for build
(defined by selecting checkbox-This build is parameterized)
Configure Jenkins System for Email Notifications
To do this:
"Jenkins Dashboard -> Manage Jenkins -> Configure System"
At the bottom of the page- find : Email Notification
Then give email notification details
I have configured like this:
SMTP server : smtp.gmail.com
Default user e-mail suffix : #gmail.com
select checkbox USE smtp authentication
give: username (without #gmail.com) -eg: enter mike for mike#gmail.com
give your password
Select checkbox Use SSL
SMTP port : 465
try your email settings by sending a test mail
If your able to send it successfuly. its done
/* In the Build - The Build is Parameterized */
1st parameter
Name : username
Default Value : mike
2nd Parameter
Name: domain
Default Value: gmail
//Post-Build Actions - Email Notification
(able to see this only when you have Mailer plugin installed)
Recipients : $username#$domain.com
This should work ..
I 'found' the solution. With a maven project, it doesn' work with the simply Email notification inside the Build properties. I must use a plugin 'Ext-mail plugin' to do it. Thanks for all.

devise forgot password email not sending

Im trying to send a forgot password email. However the following error occurs -
Net::SMTPAuthenticationError in Devise::PasswordsController#create
535-5.7.8 Username and Password not accepted. Learn more at
I manage to see the sent email within the logs file but not within my actual inbox. Any ideas on how to fix this error?
Heres my development.rb code -
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "myemail#gmail.com",
password: "mypassword"
}
Using: rails 4 and devise 3.2.3
Thanks
This error usually occurs when the associated email address is setup for 2-factor authentication. If you want to test with the same gmail account then generate an Application specific password. See details here.
If you have a another gmail account which does not require 2-factor authentication then try that one instead in your code.

How do you fix 550 must be authenticated sending Mail using Grails?

I'm using Grails Mail plugin and trying to send email and keep getting:
Error 500: Executing action [sendInvite] of controller
[RegisterController] caused exception: Failed messages:
javax.mail.SendFailedException: Invalid Addresses; nested exception
is: com.sun.mail.smtp.SMTPAddressFailedException: 550 must be
authenticated
I'm properly following the instructions at: http://www.grails.org/Mail+plugin
The mail server is returning an error when you try to send out the mail. 550 is a generic SMTP failure code; in this case it looks like you are missing a username and password. Some SMTP servers to not require authentication but most do, especially if they're publicly available on the internet. It's also possible that your SMTP server requires an SSL connection and you're connecting with an unsecured socket.
The example config for gmail shows how to set all the mail server authentication options in Config.groovy:
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "youracount#gmail.com"
password = "yourpassword"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
Add "mail.debug": "true" to props to turn on JavaMail debugging to get a better picture of what is happening before the failure.
In my case the 550 error was caused by me having accidentally selected and IMAP account as the default account but sending emails from my Outlook Connector Account (which has no authentication settings to make).
I changed the Outlook Connector Account to default. Resent the emails and no errors.
So check that the correct email account is set up as the default also