Send SMTP Email through Exchange Server Using Zend_Mail - How to Diagnose these Errors - zend-framework

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.

Related

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);

Relay access denied

I know that this question is not strictly related to coding, but I'm trusting the knowledge of this community to solve this and I thought it could still interest many people to know how to face this problem.
I am trying to send e-mails to people in a particular company, and keep getting the following error from the mail delivery system:
This is the mail delivery agent at messagelabs.com.
I was unable to deliver your message to the following addresses:
********#******.com
Reason: 554 5.7.1 <********#******.com>: Relay access denied
The message subject was: RE: ********
The message date was: **********
The message identifier was: **********
The message reference was: ************
Please do not reply to this email as it is sent from an unattended mailbox.
Please visit www.messagelabs.com/support for more details
about this error message and instructions to resolve this issue.
Last-Attempt-Date: ********
Remote-MTA: *********
Diagnostic-Code: smtp; 554 5.7.1 <********#******.com>: Relay access denied
Status: 5.7.1
Action: failed
Final-Recipient: ****; ********#******.com
Does anyone know what's going on here?
I am trying to send from a normal gmail account, straight from the web browser. It looks like I get this error only when I send e-mails to this specific domain, although we've been e-mailing in the past with no issues at all.
Thank you!

454 Error: authentication failed when using Net::SMTP::SSL to send email

I use Net::SMTP::SSL to sent email in Perl, and got "454 Error: authentication failed"
Here is my code:
use Net::SMTP::SSL;
$smtp = Net::SMTP::SSL->new($smtp2, Port => $smtp_port2, Timeout => 10, Debug => 1);
$smtp->auth($login2, $password2);
$smtp->mail($login2);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: $to\n");
$smtp->datasend("From: Aspiring error email \n");
$smtp->datasend("Date: $today\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
$smtp->datasend($message);
$smtp->dataend();
$smtp->quit;
And i got these message:
Net::SMTP::SSL=GLOB(0xf9ab80)<<< 454 Error: authentication failed, system busy
It seem i failed to auth, and i am sure the username and pw is correct.
Thanks so much!!!
454 Error: authentication failed, system busy
These are temporary problems.
The mail server is probably not doing local verification of the password, but is using an external system like a Radius or LDAP server, and the connection to this authentication system failed. Just try again later and hope that the problem got resolved.
If the credentials were wrong the server would have send a 535 status code.
See also the status codes in RFC4954.

sending mail using gmail SMTP and OAuth2.0

I got struck with this error for past 2 days of time. The objective is simple. I tried out sending emails using gmail smtp oauth and zend mailer for this work. I got this error
Fatal error: Uncaught exception 'Zend_Mail_Protocol_Exception' with message '5.5.2 Cannot Decode response iv3sm786895pbc.40 - gsmtp ' in /opt/lampp/htdocs/salaikumar/handmadeimap-master/gmailoauthexample/Zend/Mail/Protocol/Abstract.php:431
Stack trace: #0 /opt/lampp/htdocs/salaikumar/handmadeimap-master/gmailoauthexample/Zend/Mail/Protocol/Smtp.php(265): Zend_Mail_Protocol_Abstract->_expect(250, 300)
:#1 /opt/lampp/htdocs/salaikumar/handmadeimap-master/gmailoauthexample/Zend/Mail/Transport/Smtp.php(207): Zend_Mail_Protocol_Smtp->mail('saravanan1115#g...')
:#2 /opt/lampp/htdocs/salaikumar/handmadeimap-master/gmailoauthexample/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail()
:#3 /opt/lampp/htdocs/salaikumar/handmadeimap-master/gmailoauthexample/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
:#4 /opt/lampp/htdocs/salaikumar/handmadeimap-master/gmailoauthexample/send.php(292): Zend_Mail->send(Object(Zend_Mail_Transport_Smtp))
:#5 /opt/lampp/htdocs/salaikumar/handmadeimap-mas in /opt/lampp/htdocs/salaikumar/handmadeimap-master/gmailoauthexample/Zend/Mail/Protocol/Abstract.php on line 431
Any one help me out with this? I referred this blog to create a Xoauth.php http://piecewiseinc.blogspot.in/2013/02/send-mail-with-gmail-smtp-and-xoauth.html. I saw a same post about this in over here. But this is dint help out. Problems sending an email to google's SMTP server (with own php script).

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