I want to send an email via Gmail in MATLAB R2015a. This is my code:
my_default_email_address = 'mygmail#gmail.com';
my_username = 'mygmail';
my_password = 'mypass';
setpref('Internet','E_mail',my_default_email_address);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',my_username);
setpref('Internet','SMTP_Password',my_password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class','javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
sendmail('recipient#example.com' , 'subject of the email', 'text of the email');
but it doesn't work and it returns these errors:
Error using send mail (line 171)
Authentication failed.
Error in email (line 14)
sendmail('recipient#example.com' , 'subject of the email', 'text of the email');
I even opened and logged on to my Gmail in a browser, but it still throws this error. Can anyone help me?
I believe your username should include the domain name as well. Set my_username to mygmail#gmail.com and try again.
Edit: Make sure access for less secure apps is turned on. Read more here.
Related
This is my first post so please be gentle.
I've been trying to send automatic SMTP emails via PHPMailer using my webhost as the server. Below is the script I am using.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require '../PHPMailer/src/Exception.php';
require '../PHPMailer/src/PHPMailer.php';
require '../PHPMailer/src/SMTP.php';
//Load Composer's autoloader
//require 'vendor/autoload.php';
//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 4; //SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Mailer = "smtp";
$mail->Host = 'surrey.redbackinternet.net';
$mail->SMTPAuth = true;
$mail->Username = 'noreply#mydomain.com';
$mail->Password = 'password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
//Recipients
$mail->setFrom('noreply#mydomain.com', 'xxx');
$mail->addAddress('contact#mydomain.com');
//Content
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
Previously, I was using Gmail as the server, which worked fine, but now I want to change this. When I run the script with the new details I get authentication error - "SMTP ERROR: Password command failed: 535 Incorrect authentication data". The full PHPMailer script log is shown in the image below.
PHPMailer log
I know the username and passwords used are correct and have seen this error seems to be returned whenever a connection cannot be established. I have a hunch it's related to my email DNS settings, though I could be completely wrong here. When I check my DNS and MX settings using dnschecker.org all seems ok as far as I can naively tell. But using hardenize.com I see my domain fails their mail server and email TLS checks. The information provided is lacking but it does say "A network error occurred while we were trying to communicate with a server. Error message: java.net.SocketTimeoutException: Read timed out". I should add here that my site uses Cloudflare as a CDN.
Any ideas on what the issue is or how to resolve it?
Thanks in advance.
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.
I'm trying to send an email using CakePHP 1.3 and I'm getting this error message:
"SMTP server error: 4.7.1 : Relay access denied"
The code for sending email is as below:
this->set('username',$username);
$this->set('pass',$pass);
$this->Email->fromName = Configure::read('from_team');
$this->Email->to = $to;
$this->Email->subject = 'New Password';
$result = $this->Email->send();
Any ideas?
It was due to invalid SMTP settings. I have detected it and solved it.
I have the following code:
$config = array(
'auth' => 'login',
'username' => 'domain\user',
'password' => 'password',
'ssl' => 'tls',
'port' => 25,
);
$tr = new Zend_Mail_Transport_Smtp('192.168.101.11',$config);
Zend_Mail::setDefaultTransport($tr);
$mail = new Zend_Mail();
$mail->setBodyText($text);
$mail->setFrom('noreply#domain.com');
$mail->addTo($user->getEmail());
$mail->setSubject('Email subject');
$mail->send();
When I try to connect using what should be the correct credentials I get the following error in the log:
2010-10-12T13:00:59-07:00 ERR (3): AdminController::emailPassword - 5.7.1
2010-10-12T13:00:59-07:00 ERR (3): AdminController::emailPassword - #0 /usr/share/php/Zend/Mail/Protocol/Smtp.php(261): Zend_Mail_Protocol_Abstract->_expect(250, 300)
#1 /usr/share/php/Zend/Mail/Transport/Smtp.php(207): Zend_Mail_Protocol_Smtp->mail('noreply#domain...')
#2 /usr/share/php/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail()
#3 /usr/share/php/Zend/Mail.php(1178): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
...
When I try to connect and send an email using a definitely bad password I get the following error:
2010-10-12T13:03:52-07:00 ERR (3): AdminController::emailPassword - 5.7.3
2010-10-12T13:03:52-07:00 ERR (3): AdminController::emailPassword - #0 /usr/share/php/Zend/Mail/Protocol/Smtp/Auth/Login.php(95): Zend_Mail_Protocol_Abstract->_expect(235)
#1 /usr/share/php/Zend/Mail/Protocol/Smtp.php(217): Zend_Mail_Protocol_Smtp_Auth_Login->auth()
#2 /usr/share/php/Zend/Mail/Transport/Smtp.php(200): Zend_Mail_Protocol_Smtp->helo('localhost')
#3 /usr/share/php/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail()
#4 /usr/share/php/Zend/Mail.php(1178): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#5 /var/www/mreserve/application/controllers/AdminController.php(458): Zend_Mail->send()
...
My problem, I don't really know how to diagnose these errors. Where do I look up what 5.7.1 and 5.7.3 error codes are described, etc? Google wasn't helping me too much. When I plug in the credentials for my personal GMail account I am able to send mail just fine, so I know that I can send emails when configured correctly.
A few other possibly helpful tidbits, I am trying to send from a company Exchange that has created an email account for this user, I am trying to send to an email outside of the domain, and I don't have a lot of access to the exchange server- other than a few screenshots on how they set up their email clients.
These are NDR (Non Delivery Report) codes for Exchange server.
Here is a (rather old) blog entry describing them, and another page listing the sames codes for exchange 2007.
5.7.1 Error code
"permission problem", which could point to a:
a SMTP relay problem. Your account is not authorized to send emails to another domain.
a sender/receiver problem. Your account is not authorized to send emails to a discussion list (because your account is not a member of it)
other specific restrictions on your account.
IMHO, only the SMTP logs can tell the exact cause.
5.7.3 Error code
"sender prohibited" or "Not Authorized, security problem", depending on the source; could be consistent with wrong password submission.
Hope this helps.
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