I am trying to send mail by connecting to Google SMTP server using oAuth2 mechanism.
public static Transport connectToSmtp(String smtpServer, int port, String email, String authToken, boolean isDebug, MimeMessage mimeMsg)
throws Exception
{
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.sasl.enable", "true");
props.put("mail.smtp.sasl.mechanisms", "XOAUTH2");
props.put("mail.imaps.sasl.mechanisms.oauth2.oauthToken", authToken);
Session session = Session.getInstance(props);
session.setDebug(isDebug);
final String emptyPassword = "";
Transport transport = session.getTransport("smtp");
transport.connect(smtpServer, port, email, emptyPassword);
try
{
transport.sendMessage(mimeMsg, mimeMsg.getAllRecipients());
}
catch (Exception e)
{
logger.log(Level.WARNING, "Exception Occured : ", e);
}
return transport;
}
Client ID and Secret of my App:
ID - 345101*-i6ki*4tk1sms.apps.googleusercontent.com
Secret - e6NHB*-eZ-rk
The above code threw the following error:
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/answer/14257 o135sm276925ith.4 - gsmtp
Smtp Server : aspmx.l.google.com,
Port : 25
Edited:
I have changed the below for the Google App account I am trying to connect and the above exception was cleared:
No 2 step authentication
Allow Less Secure Apps
"Security" -> "Basic Settings" -> "Go to settings for less secure apps" -> "Allow Users to Manager Their Access to Less Secure Apps"
But after clearing the above exception. I got another exception.
com.sun.mail.smtp.SMTPSendFailedException: 550-5.7.1 Invalid credentials for relay [121...2]. The IP address you've registered in Google Apps SMTP Relay service doesn't match domain of the account this email is being sent from. If you are trying to relay mail from a domain that isn't registered under your Googles Apps account or has empty envelope-from, you must configure your mail server either to use SMTP AUTH to identify the sending domain or to present one of your domain names in the HELO or EHLO command. For more information, please visit https://support.google.com/a/answer/6140680#invalidcred f65sm341248ith.1 - gsmtp
;
So I changed the following setting:
Apps > Google Apps > Gmail > Settings for Gmail > Advanced settings
SMTP relay service
Allowed senders: Any addresses (not recommended)
Only accept mail from the specified IP addresses: No
Require SMTP Authentication: Yes
Require TLS encryption: No
Even after attempting the above change the same exception is thrown.
Please help.
Plain authentication and OAuth2 must be differentiated in Transport object which sends actual mail data to the SMTP server.
This is done in JavaMail with the password parameter in Transport.connect().
If the password is given as null in the above code, then the Java MailClient treats the authentication as OAuth instead of plain auth.
So the code should be
final String emptyPassword = null;
As reply to the comment,
If authentication is given as IP Address, then the given username and password are not validated. Instead, the IP address from which the connection comes from serves as authentication.
This is the reason the same code worked, when you added the sender IP address to the GApps Relay Mail Settings and select authentication type as IP address.
Related
When I try to send a message via smtp, the error message "550 5.7.60 SMTP Client does not have permissions to send as this sender" appears.
If I give myself a send as permission on my own Mailbox, the whole thing works.
I tried to connect via telnet and found that the authentication is NTML.
The Receive connector is configured correct.
I use an Exchange Server 2019.
I am trying to setup Sendinblue and use it as an SMTP server for my marketing and general Odoo 12 email messaging.
I setup every thing in Sendinblue and tested the SMTP Server in Odoo and got a "sucess" message under Settings / Technical / Outgoing Mail Servers.
For this I setup an external smpt server with the following data:
SMTP Server: smtp-relay.sendinblue.com
Email: my sendinblue email
Password: Password provided by sendinblue
Port: 587
Security: TLS (STARTTLS)
I can test the connection with success and set this SMTP Server as the server for sending email campaigns from Email Marketing / Settings / General Settings
Created a test email campaign and tried to send it and test it with no luck.
When Odoo tries to send the message, returns a "not delivered email" message with a unique reference and my local PC name, something like:
989345297097442.1625436965.401543280300903-openerp-reply_to#MYPC-NAME
I confirm sender email is registered and validated in Sendinblue. Using the same email as sender in Odoo.
Tried to do the same with my personal gmail account but even activating less secure apps, no message is sent from my instance.
What could be wrong?
I found the problem.
I had to verify the domain name I use for sending emails from Sendinblue service.
I have done it Senders & API main menu option on "domain" tab.
After verifying my domain name, everything is running fine
We set up a VM in Windows Azure cloud service. However, the SMTP is not working. All the messages are queuing in the mailroot\queue folder. Here are some delivery failure message received.
Delivery Status Notification (Failure)
Action: failed
Status: 5.5.0
Diagnostic-Code: smtp;550-5.7.1 [x.x.x.x] The IP you're using to send mail is not authorized to 550-5.7.1 send email directly to our servers. Please use the SMTP relay at your
550-5.7.1 service provider instead.
Delivery Status Notification (Failure)
Action: failed
Status: 5.5.0
Diagnostic-Code: smtp;550 OU-002 (COL0-MC1-F41) Unfortunately, messages from x.x.x.x weren't sent. Please contact your Internet service provider since part of their network is on our block list.
How can it be solved? Please help. Thanks
That looks to me as though the receiving hosts are blocking you from sending to them, probably because your IP is on a blocklist. You can check that on http://mxtoolbox.com/blacklists.aspx
You might want to raise a support ticket with Azure and complain, and/or alternatively ask them for their SMTP server settings, which will relay the mail through their servers (which should never be blocked).
Youtrack allow to send email through 3rd party SMTP server. Fields are as follows:
SMTP host: [?]
SMTP port: [?]
Mail protocol: [?]
SMTP login: [?]
SMTP password: [?]
Select SSL key: [?]
Server 'from' email: [?]
Could you provide an example of Gmail or Google apps config ?
Here is what I finally did:
SMTP host: smtp.gmail.com ;
SMTP port: 465 ;
Mail protocol: SMTP+SSL ;
SMTP login: user#domain.com or user#gmail.com ;
SMTP password: ****** ;
Select SSL key: No key ;
Server 'from' email: user#domain.com.
Gmail will ignore the from parameter so I put the same.
References
Enable IMAP in your Gmail settings (Gmail doc) ;
How to use Gmail as your SMTP server.
I was using 2-Step Verification on my Gmail Account and this caused an error sending an email. To resolve first I created an App Password (see: https://support.google.com/accounts/answer/185833)
NOTE: to be able to create an App Password it's absolutely necessary to enable 2-Step Verification in your google account. If you don't do it, you'll receive a message indicating that your account doesn't support App Passwords.
Then using these settings I was able to send a test email:
SMTP host: smtp.gmail.com
SMTP port: 465 ;
Mail protocol: SMTP+SSL
SMTP login: user#gmail.com
SMTP password: #newly created app password# ;
Select SSL key: No key ;
Server 'from' email: user#domain.com.
The other two answers are correct, but are alternatives:
if your google account is configured to use 2-step verification you must use an AppPaswword. In this case you cannot enable less secure apps.
if your google account is not configured to use 2-step verification, you must enable less secure apps, and log to your account from a browser in the machine where youtrack is installed (as pointed out in the comment). In this case you cannot create App Passwords.
Additional notes:
as you can see, the youtrack configuration is the same in both cases, save for the password, which is the AppPassword if you use the first option, or the account password, if you use the second one.
in the from email, the email account is ignored, but you can specify a friendly name if you use this syntax: "Friendly Name <myacount#gmail.com>" When someone receives a notification he'll see From: Friendly Name. The account, whichever you specify, will be replaced by the google account you're configuring.
Minor addition to other answers.
My account have no 2-step verification, but with this solution I didn't have to log in from browser on YouTrack server machine, neither didn't have to enable less secure apps.
Config:
SMTP Host: smtp.gmail.com
SMTP Port: 587
Mail Protocol: SMTP+TLS
SMTP Login: user#gmail.com
SMTP Password: ****** (account password)
Select SSL key: (Nothing selected)
From address: YouTrack <user#domain.com>
Next:
Try to send test email (the button right below youtrack config).
It will fail.
Now just login into google account from your regular browser.
You'll get a warning about recent blocked login attempt.
Open warning and verify the login attempt from IP of your youtrack server.
Done. Now you should be able to send test email successfully.
Is there anyway to check or validate the username and password assigned to an exchange service before getting a url ?
In my program now , I create a new service and assigned username and password to it as follows
var service = new ExchangeService(exchangeVersion) { Credentials = new WebCredentials(userSmtp, password) };
service.AutodiscoverUrl(userSmtp, RedirectionUrlValidationCallback);
If there is something wrong with the credentials (e.g. wrong password), the exception will be
"Autodiscover service couldn't be located".
The problem with this method that it does not really specify the reason for not being able to bring the url. So is there any way that I can know why exactly I am unable to locate the the service? for example I would like to see an exception message saying that wrong username or password.
Can anyone help me with that ?
Have a look at the Microsoft Remote Connectivity Analyzer # https://www.testexchangeconnectivity.com/
You can test:
-Microsoft Exchange ActiveSync Connectivity Tests
-Microsoft Exchange Web Services Connectivity Tests
-Microsoft Office Outlook Connectivity Tests
-Internet Email Tests