how to send an email using Godaddy webmail in Springboot aplication - java

When can successfully send email using Gmail but when I use Godaddy webmail I get the following:
Failed message 1: javax.mail.MessagingException: Could not connect to SMTP
host: smtpout.asia.secureserver.net, port: 465, response: -1] with root
cause
javax.mail.MessagingException: Could not connect to SMTP host:
smtpout.asia.secureserver.net, port: 465, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2106) ~
[javax.mail-1.5.6.jar:1.5.6]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712) ~
[javax.mail-1.5.6.jar:1.5.6]
at javax.mail.Service.connect(Service.java:366) ~[javax.mail-
1.5.6.jar:1.5.6]
Here is my properties file
spring.mail.host = smtpout.asia.secureserver.net
spring.mail.username= xyz#domian.com
spring.mail.password= ******
spring.mail.properties.mail.transport.protocol=smtp
spring.mail.properties.mail.smtp.port=465
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.timeout=60000
spring.mail.properties.mail.imap.ssl.enable=true
spring.mail.properties.mail.imap.ssl.trust=*
Here is My code
//SendMail using java Mail API
#Autowired
JavaMailSender mailSender;
public String send(String to, String Subject, String Password) throws
MessagingException{
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper;
helper = new MimeMessageHelper(message, true);
helper.setSubject(Subject);
helper.setTo(to);
helper.setText("Your password is:"+Password);
mailSender.send(message);
return "false";
}

This issue is not related to JAVA code, its seems to be issue on your server settings with SMTP protocol.
However I suspect you might missed some thing in your SMTP configuration in JAVA, I will suggest below pointers about it.
Configure a local SMTP server as a relay on your locally, just to
check you are on right track.
You can even configure dummy server to trace the email request.
Check your firewall settings as well, possible it might be restricted
for other SMTP server.

I had this very same problem - and was about to get crazy - when I found a working solution here in Stackoverflow, though I've lost the link, I'm sorry.
In this - legacy - project, I was using Spring 3.x. Mail was sent with org.springframework.mail.javamail.JavaMailSenderImpl and configured like this:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.server.host}" />
<property name="port" value="${mail.server.port}" />
<property name="protocol" value="${mail.server.protocol}" />
<property name="username" value="${mail.server.username}" />
<property name="password" value="${mail.server.password}" />
<property name="javaMailProperties">
<util:properties location="classpath:javamail.properties" />
</property>
</bean>
Someone suggested to use this configuration:
mail.server.protocol=smtps
mail.smtps.quitwait=false
mail.smtp.auth=true
mail.smtp.starttls.enable=true
And that worked fine.
Beware the protocol is smtps in some properties but in others is smtp.

Thakur!
I was getting the exact same error you are, but now I got a solution based on your code.
Try to add into your properties the following:
spring.mail.properties.mail.smtp.ssl.enable=true
spring.mail.properties.mail.smtp.ssl.trust=*
Your problem is happening because GoDaddy requires SSL in their connection requests, otherwise they won't answer your request! Also, I used https://www.smtper.net to test my smtp connection and see if it worked. You can use it to check if your problem is the missing SSL too.

I'm using Spring Boot 2.2 an works with this configuration:
spring.mail.host=smtpout.secureserver.net
spring.mail.port=465
spring.mail.username=your_email#example.com
spring.mail.password=your_password
# Other properties
spring.mail.properties.mail.smtp.auth=true
# TLS, port 587
#spring.mail.properties.mail.smtp.starttls.enable=true
# SSL, port 465
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
When you use gmail the protocol is TLS generally, but GoDaddy looks like use only SSL, so I comment the TLS config and enable the SSL config.
You must set de field from when you send the email (the same in spring.mail.username) or get an error:
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("your_email#example.com");
...
Hope can help you.
PD: after google a lot I finded the solution in: https://mkyong.com/spring-boot/spring-boot-how-to-send-email-via-smtp/

Related

STARTTLS issue when using google as the smtp server when using javamail

I use the Java based CMS dotCMS and I want to use google as the smtp server. I used the config as described in the dotCMS docs: http://dotcms.com/docs/latest/mail-configuration.
My config looks like this:
<Resource
name="mail/MailSession"
auth="Container"
type="javax.mail.Session"
mail.debug="true"
mail.transport.protocol="smtp"
mail.smtp.host="smtp.gmail.com"
mail.smtp.auth="true"
mail.smtp.port="465"
mail.smtp.starttls.enable="true"
mail.smtp.user="[my username]"
mail.password="[my pwd]"
username="[my username]"
password="[my pwd]"
mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
/>
When I call the $mailer.sendEmail method I get an error back:
"Unable to Send Message: 530 5.7.0 Must issue a STARTTLS command first. c7sm25357283wjb.19 - gsmtp".
I also tried port 587, but that did not help either.
Any idea what I am doing wrong? I'm using dotcms 2.5.6. running on debian 7.8 (wheezy)
You shouldn't need the socketFactory setting.
You also shouldn't need the port setting.
Try setting mail.smtp.ssl.enable=true. If that doesn't work, try setting mail.transport.protocol=smtps and change all the mail.smtp.* settings to mail.smtps.*.
The Gmail entry in the JavaMail FAQ might be useful.
If none of that works, post the JavaMail debug output.
Do you have 2 factor authentication set up in google? I think this might prevent the authentication from happening.

Spring JMS Listener doesnt connect to ActiveMQ

i want to use the Spring JMSListener infrastructure. So i set up an ActiveMQ instance and tried to do a simple test. Here is my spring config:
<!-- ActiveMQ Configuration -->
<jms:annotation-driven/>
<!-- JMS ConnectionFactory to use, configuring the embedded broker using XML -->
<bean id="jmsConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://xxxx.xxxx.net:8161" />
</bean>
<bean id="jmsListenerContainerFactory"
class="org.springframework.jms.config.DefaultJmsListenerContainerFactory">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
<property name="concurrency" value="3-10"/>
</bean>
Of course i have a simple class like this:
#Component
public class MessageListenerExample {
#JmsListener(destination = "TestQueue")
public void doSomething(String message) {
System.out.println("OnMessage Received :" + message);
}
}
Now when i startup the spring based application. i see in the debugger that my listener methods gets registered but somehow Spring doesnt connect to the ActiveMQ queue, which i can see easily by looking in the activeMQ web console. Furthermore i dont see any logging output from spring what the JMS stuff does.
Do i miss something? Whats the best way to go from here? Of course i also tested to send a message from within the web console of ActiveMQ but w/o a client connection, there is no hope of delivery. Thanks for any input.
Update: i found a stacktrace...
[WARN 14:02:58] DefaultMessageListenerContainer.handleListenerSetupFailure(860) | Setup of JMS message listener invoker failed for destination 'TestQueue' - trying to recover. Cause: The JMS connection has failed: Unknown data type: 47
org.apache.activemq.ConnectionFailedException: The JMS connection has failed: Unknown data type: 47
at org.apache.activemq.ActiveMQConnection.checkClosedOrFailed(ActiveMQConnection.java:1480)
at org.apache.activemq.ActiveMQConnection.createSession(ActiveMQConnection.java:324)
at org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:192)
at org.springframework.jms.listener.DefaultMessageListenerContainer.access$1400(DefaultMessageListenerContainer.java:122)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1162)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1141)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1134)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1031)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Unknown data type: 47
at org.apache.activemq.openwire.OpenWireFormat.doUnmarshal(OpenWireFormat.java:365)
at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:285)
at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:221)
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:213)
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)
... 1 more
Because I looked in the wrong log, I have not seen the obvious. I am posting this because this is something many could stumble over.
I defined the wrong port in the spring config. I mistakenly used the web console port but I wanted of course the TCP transport being used which lives on port 61616.
This was mentioned by Bruce Snider somewhere in the web as a reply the same problem.

Mail Server with javax.mail and CentOS

I have a Java Program that was installed on an old Ubuntu machine and sent mail using javax.mail. However, that machine went down and I am now running the same Java app in a new CentOS machine.
However, I get an error "MessagingException: 501 Syntax: HELO hostname" when trying to send an email using mail.smtp.host = 127.0.0.1.
My guess is that the mailserver is not yet activated in this CentOS.
How would I go about configuring a mail server that javax.mail can use?
Thank you
Your machine host name must be mapped in /etc/hosts file.
Example:
Console shows: linux#
and cat /etc/hostname shows
linux.mydomain.com
Then edit your hosts file running as root . vi /etc/hosts
127.0.0.1 localhost linux linux.mydomain.com
Good detailed info can be found here: https://confluence.atlassian.com/display/CONFKB/Sending+Email+Fails+Due+to+501+Syntax%3A+HELO+Hostname+Error
I encountered the same issue "MessagingException: 501 Syntax: HELO hostname" when sending out email with Spring MailSender. What works for me is to add in extra property "mail.smtp.localhost" under javaMailProperties like below:
<!-- JAVA MAIL -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="" />
<property name="port" value="25" />
<property name="protocol" value="smtp" />
<property name="username" value="" />
<property name="password" value="" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtps.auth">true</prop>
<prop key="mail.smtps.starttls.enable">true</prop>
<prop key="mail.smtps.debug">true</prop>
<prop key="mail.smtp.localhost">localhost</prop>
</props>
</property>
</bean>
The problem is that the naming service on the new machine is not properly configured and Java can't find the host name of the machine. The SMTP HELO command needs to include the host name. The server is complaining because it's missing. Turn on JavaMail Session debugging and you can see the actual command this is sent. You can work around this host configuration problem by setting the JavaMail property mail.smtp.localhost to be the host name you want to use in the HELO command.
You need to run sendmail. See here for more info. Configuring sendmail can be a chore and you may want to take the configuration sendmail.cf from the old machine if possible.
I suspect (also) that you should have some central MTA (mail transport agent) set up, such that all machines in your enterprise use this, rather than running one per host. i.e. not using localhost.
In my case etc/hostname was susetest(and not linux.company.com)
Modified etc/hosts from 127.0.0.1 localhost to 127.0.0.1 localhost susetest(also after localhost make sure to use tab, when modifying the file)
Make sure to save changes, postfix stop, postfix start to restart SMTP server.
Should work fine.
(adding properties.setProperty("mail.smtp.localhost", "ourcompany.com"); to the properties also solved the problem, but workaround should not be the fix, when you can find the root cause, even if it takes days in my case)

Unable to send an email using SMTP (Getting javax.mail.MessagingException: Could not convert socket to TLS;)

I have written the following code for sending email using javamail API through SMTP as TLS as SSL is not supported but I ended up with the following exception. Please see my code below. I have used debugging mode and below the code you can find the exception as well.
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMailTLS {
public static void main(String[] args) {
final String username = "---------#mydomain.com";
final String password = "***********";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "mail.mydomain.com");
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
session.setDebug(true);
try {
Message message = new MimeMessage(session);
message.setFrom(new
InternetAddress("---------#mydomain.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("---------#mydomain.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
Exception trace
DEBUG: setDebug: JavaMail version 1.4.5
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "mail.mydomain.com", port 587, isSSL false
220-cpanel35.per.syra.net.au ESMTP Exim 4.80 #2 Fri, 05 Oct 2012 17:28:56 +0800
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
DEBUG SMTP: connected to host "mail.mydomain.com", port: 587
EHLO xxxxxx.xxxxx.com
250-cpanel35.per.syra.net.au Hello xxxx.xxxxx.com [xx.xx.xx.xxx]i
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
STARTTLS
220 TLS go ahead
Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
at SendMailTLS.main(SendMailTLS.java:52)
Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1918)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:652)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at SendMailTLS.main(SendMailTLS.java:47)
Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1868)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1826)
at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1809)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1328)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1305)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:548)
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:485)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1913)
... 7 more
Caused by: java.lang.RuntimeException: Could not generate DH keypair
at sun.security.ssl.DHCrypt.<init>(DHCrypt.java:123)
at sun.security.ssl.ClientHandshaker.serverKeyExchange(ClientHandshaker.java:618)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:202)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:998)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1294)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1321)
... 11 more
Caused by: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)
at com.sun.crypto.provider.DHKeyPairGenerator.initialize(DHKeyPairGenerator.java:120)
at java.security.KeyPairGenerator$Delegate.initialize(KeyPairGenerator.java:658)
at sun.security.ssl.DHCrypt.<init>(DHCrypt.java:117)
... 18 more
Can anyone help me debug this? Thanks in advance!
Commenting-out the property mail.smtp.starttls.enable means you fall back to a default and unsecured connection, which would work only if the remote SMTP host also accepts unsecured transport on port 587 (the port for mail submission versus port 25 for end-delivery or relay operations).
In my context, TLS is compulsory on 587 and any attempt to open a session without TLS yield the SMTP server error response 530 Must issue a STARTTLS command first.
Then setting mail.smtp.starttls.enable to true alone still yield the same error Could not convert socket to TLS but now with a clue: Server is not trusted. Indeed, you must have either a keystore defined in the JVM start properties that would contain a certificate chain ending onto a trusted root certificate, either enforce trust with this extra property: mail.smtp.ssl.trust set to the remote host name.
Configuring the whole stuff in Spring support for javamail for instance (which you can easily map to plain javamail API) requires all of the following:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="theRemoteSmtpServer" />
<property name="port" value="587" />
<property name="username" value="muUserID" />
<property name="password" value="myPassword" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtp.ssl.trust">theRemoteSmtpServer</prop>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
</bean>
I resolved this issue by just commenting out the below property
props.put("mail.smtp.starttls.enable", "true");
and the code got executed with no errors or warning or simply delete this line from the above source code. It is working like a charm till date.
Make sure your antivirus software is not blocking the application. In my case Avast was blocking me from sending e-mails in a Java SE application.
I had a same issue with smtp.gmail.com and fixed with the following steps
changed my code as per berhauz comments
changed in Gmail settings from this link: https://www.google.com/settings/security/lesssecureapps
Maybe this issue related to security and smtp.ssl is not trusted that's why issue occurs.
I resolve this issue just add a property
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com
Now it is working fine for me.
If you don't want to use SSL, and you're using smtp instead of smtps try these settings
mail.smtp.starttls.enable=false
mail.transport.protocol=smtp
It looks like the SSL implementation used by your server is not compatible with the SSL implementation in the version of the JDK you're using. The file SSLNOTES.txt (also included in the JavaMail download bundle) has some debugging tips. You might need a JDK SSL expert to sort this out.
I had this problem. the reason was our administrator had blocked TLS and SSL protocols.
session.getProperties().put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.ssl.trust", "smtp.office365.com(site where your account is)");
props.put("mail.smtp.starttls.enable", true);
These codes should be able to start a ttls communication and get the mail service running.
In addition to this the antivirus creates a firewall that stops the handshake from happening.
After fighting all day this works for me (using spring boot , MailSender , aws)
spring.mail.host=smtp.gmail.com
spring.mail.username=-----------#gmail.com
spring.mail.password=--------------
spring.mail.properties.mail.transport.protocol=smtp
spring.mail.properties.mail.smtp.port=465
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.ssl.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com
I spent hours on this error, until I found out that tomcat used TLS version 1.1 while the smtp server supports only TLS 1.2 and 1.3.
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
Setting TLS version to 1.2 solved my problem
The stack trace reveals that the actual cause of the problem is this:
java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)
You are running into a limitation of older versions of Java that did not support DH primes longer than 1024 bits, which your SMTP server was probably requiring. Here are the relevant bug entries:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6521495
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7044060
This restriction/limitation was removed in Java 8 (see the release notes).
Note that as has been pointed out already, your "fix" of disabling STARTTLS is not a real fix: It means your password will be sent as plain text, plus this will only work for SMTP servers that allow unencrypted traffic on port 587.
I resolved this issue by disabling my virus guard.
Q) Could not convert socket to TLS & Server is not trusted issue?
Ans: I also faced same issue, just add below code in application.properties file then it will resolve.
Below code for application.yml file.
spring:
mail:
host: smtp.gmail.com
port: 587
username: yourid#gmail.com
password: yourpassword
protocol: smtp
properties:
mail:
smtp:
starttls:
enable: true
required: true
auth: true
ssl:
trust: smtp.gmail.com
Below code for application.properties file.
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=yourid#gmail.com
spring.mail.password=yourpassword
spring.mail.protocol=smtp
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com

Unrecognized SSL message, plaintext connection? Exception

I have a java complied package to speak with the https server on net. Running the compilation gives the following exception:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
I think this is due to the connection established with the client machine is not secure. Is there any way to configure the local machine or ports in order to connect to the remote https server?
I think this is due to the connection
established with the client machine is
not secure.
It is due to the fact that you are talking to an HTTP server, not an HTTPS server. Probably you didn't use the correct port number for HTTPS.
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
You should have a local SMTP domain name that will contact the mail server and establishes a new connection as well you should change the SSL property in your programming below
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection
props.put("mail.smtp.socketFactory.fallback", "true"); // Should be true
I got the same error message when I forgot to log in to the company firewall, before performing a POST request through a proxy.
I got the same error. it was because I was accessing the https port using http.. The issue solved when I changed http to https.
Adding this as an answer as it might help someone later.
I had to force jvm to use the IPv4 stack to resolve the error. My application used to work within company network, but while connecting from home it gave the same exception. No proxy involved. Added the jvm argument
-Djava.net.preferIPv4Stack=true and all the https requests were behaving normally.
If you are running local using spring i'd suggest use:
#Bean
public AmazonDynamoDB amazonDynamoDB() throws IOException {
return AmazonDynamoDBClientBuilder.standard()
.withCredentials(
new AWSStaticCredentialsProvider(
new BasicAWSCredentials("fake", "credencial")
)
)
.withClientConfiguration(new ClientConfigurationFactory().getConfig().withProtocol(Protocol.HTTP))
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("localhost:8443", "central"))
.build();
}
It works for me using unit test.
Hope it's help!
I face the same issue from Java application built in Jdevelopr 11.1.1.7 IDE. I solved the issue by unchecking the use of proxy form Project properties.
You can find it in the following:
Project Properties -> (from left panle )Run/Debug/Profile ->Click (edit) form the right panel -> Tool Setting from the left panel -> uncheck (Use Proxy) option.
i solved my problem using port 25 and Following prop
mailSender.javaMailProperties.putAll([
"mail.smtp.auth": "true",
"mail.smtp.starttls.enable": "false",
"mail.smtp.ssl.enable": "false",
"mail.smtp.socketFactory.fallback": "true",
]);
In case you use Jetty version 9 or earlier you need to add it to jetty
by
RUN java -jar ${JETTY_HOME}/start.jar --add-to-startd=https
and according to this
Jetty: How to use SSL in Jetty client side
from Jetty version 10 it should work out of the box
In case you are running
Cisco AnyConnect Secure Mobility Agent
Cisco AnyConnect Web Security Agent
try stopping the service(s).
In our corporate network this IS the solution to the issue.
It worked for me now, I have change the setting of my google account as below:
System.out.println("Start");
final String username = "myemail#gmail.com";
final String password = "************";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "465");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Transport transport=session.getTransport();
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("myemail#gmail.com"));//formBean.getString("fromEmail")
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("myemail#gmail.com"));
message.setSubject("subject");//formBean.getString(
message.setText("mailBody");
transport.connect();
transport.send(message, InternetAddress.parse("myemail#gmail.com"));//(message);
System.out.println("Done");
} catch (MessagingException e) {
System.out.println("e="+e);
e.printStackTrace();
throw new RuntimeException(e);
}
Though I have enabled SSL and TSL while running program in this link of same post. I spend a lot of time but than I realized and found this link.
And done 2 following steps and setting control in google. :
Disable the 2-step verification (password and OTP)
Enabling to allow to access less secure app(Allow less secure apps:
ON.)
Now I am able to send mail using above program.
As EJP said, it's a message shown because of a call to a non-https protocol.
If you are sure it is HTTPS, check your bypass proxy settings, and in case add your webservice host url to the bypass proxy list
if connection is FTPS test:
FTPSClient ftpClient = new FTPSClient(protocol, false);
protocol = TLS,SSL
and false = isImplicit.
I got the same issue and it got resolved by setting "proxyUser" and "proxyPassword" in system properties.
System.setProperty("http.proxyUser", PROXY_USER);
System.setProperty("http.proxyPassword", PROXY_PASSWORD);
along with "proxyHost" and "proxyPort"
System.setProperty("http.proxyHost", PROXY_ADDRESS);
System.setProperty("http.proxyPort", PROXY_PORT);
Hope it will work.
I was facing this exception when using Gmail.
In order to use Gmail I had to turn ON "Allow less secure apps".
This Gmail setting can be found at https://www.google.com/settings/security/lesssecureapps after login the gmail account.
I've got similar error using camel-mail component to send e-mails by gmail smtp.
The solution was changing from TLS port (587) to SSL port (465) as below:
<route id="sendMail">
<from uri="jason:toEmail"/>
<convertBodyTo type="java.lang.String"/>
<setHeader headerName="Subject"><constant>Something</constant></setHeader>
<to uri="smtps://smtp.gmail.com:465?username=myemail#gmail.com&password=mypw&to=someemail#gmail.com&debugMode=true&mail.smtp.starttls.enable=true"/>
</route>
Maybe your default cerficate has expired. to renew it through admin console go "Security >SSL certificate and key management > Key stores and certificates > NodeDefaultKeyStore > Personal certificates" select the "default" alias and click on "renew" after then restart WAS.
If you're running the Java process from the command line on Java 6 or earlier, adding this switch solved the issue above for me:
-Dhttps.protocols="TLSv1"

Categories

Resources