I am trying to send mail using SMTP in Java. Below are the details:
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.mail.com" />
<property name="port" value="465" />
<property name="username" value="${mail.user}" />
<property name="password" value="${mail.pwd}" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtp.starttls.required">true</prop>
<prop key="mail.smtp.ssl.enabled">true</prop>
<prop key="mail.debug">true</prop>
</props>
</property>
</bean>
Error I am getting is:
535 Authentication credentials invalid
But the credentials are valid, I use the same for logging in from UI. Also, I have tried 587 and 25 port numbers, changing auth and tls values but to no avail.
SMTP settings for mail.com - https://www.lifewire.com/what-are-mail-com-smtp-settings-1170500
Note - I have tried it in both Java app and Mule 4 app
Mule 4 config:
<email:smtp-config name="Email_SMTP" doc:name="Email SMTP" doc:id="0e79558e-d0c8-42e3-b534-6d18439fc1e0" >
<email:smtp-connection host="smtp.mail.com" user="user#mail.com" password="****" connectionTimeout="10" port="587" readTimeout="10" writeTimeout="10">
<email:properties >
<email:property key="mail.smtp.auth" value="true" />
<email:property key="mail.smtp.starttls.enable" value="true" />
<email:property key="mail.smtp.starttls.required" value="true" />
<email:property key="mail.debug" value="true" />
<email:property key="mail.smtp.ssl.enable" value="true" />
</email:properties>
</email:smtp-connection>
</email:smtp-config>
Since I have faced same in both Java and Mule, I am suspecting it's something to do with the SSL or Auth properties.
Related
My question regards hazelcast-client configuration.
From what I understand, when configured properly the client is supposed to fetch hazelcast server nodes IPs automatically from the AWS api , the problem is doesn't even try connect.
Here's some log I found.
Caused by: java.lang.IllegalStateException: Unable to connect to any address in the config! The following addresses were tried: []
at com.hazelcast.client.spi.impl.ClusterListenerSupport.connectToCluster(ClusterListenerSupport.java:178)
at com.hazelcast.client.spi.impl.ClientClusterServiceImpl.start(ClientClusterServiceImpl.java:189)
also here's client conifig
<bean id="hazelcastInstance" class="com.hazelcast.client.HazelcastClient" factory-method="newHazelcastClient">
<constructor-arg>
<bean class="com.hazelcast.client.config.ClientConfig">
<property name="groupConfig">
<bean class="com.hazelcast.config.GroupConfig">
<property name="name" value="dev"/>
</bean>
</property>
<property name="properties">
<props>
<prop key="hazelcast.icmp.enabled">true</prop>
</props>
</property>
<property name="networkConfig">
<bean class="com.hazelcast.client.config.ClientNetworkConfig">
<property name="awsConfig">
<bean class="com.hazelcast.client.config.ClientAwsConfig">
<property name="insideAws" value="true" />
<property name="enabled" value="${hazelcast.aws.enabled:false}" />
<property name="region" value="${hazelcast.aws.region:set-me}" />
<property name="accessKey"value="key" />
<property name="secretKey" value="secret"/>
<property name="hostHeader" value="ec2.amazonaws.com"/>
<property name="iamRole" value="${hazelcast.aws.iam.role:#{null}}"/>
<!-- <property name="securityGroupName" value="${hazelcast.aws.securityGroupName:#{null}}" /> -->
<property name="tagKey" value="${hazelcast.aws.tagKey:hazelcast-cluster}" />
<property name="tagValue" value="${hazelcast.aws.tagValue:#{null}}" />
<property name="connectionTimeoutSeconds" value="${hazelcast.aws.connectionTimeout:15}" />
</bean>
</property>
</bean>
</property>
</bean>
</constructor-arg>
</bean>
also tried to force server ip, that works. I need the client to discover server ips automatically. any clue ?
You need to use the discovery plugin mechanism if you want the client to discover clusters on AWS (or any other cloud). The old AWS discovery was for members only.
Please see https://github.com/hazelcast/hazelcast-aws
I am using JavaMailSender and Spring to send emails.
I instantiate the JavaMailSender load it as a property of the mailer bean and autowire the mailer bean to my controller.
I load it with the following properties:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="port" value="587" />
<property name="username" value="email#email.com" />
<property name="password" value="password" />
<property name="javaMailProperties">
<props>
<prop key="mail.debug">true</prop>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.mime.charset">UTF-8</prop>
<prop key="mail.transport.protocol">smtp</prop>
</props>
</property>
</bean>
<bean id="mailer" class="mz.co.crunchtech.vtchill.utils.Mailer">
<property name="mailSender" ref="mailSender" />
<property name="velocityEngine" ref="velocityEngine"/>
</bean>
I pass the mailer object around on my worker threads so every once in a while i get the following error:
Exception in thread "taskExecutor-50"
org.springframework.mail.MailAuthenticationException: Authentication
failed; nested exception is javax.mail.AuthenticationFailedException:
454 4.7.0 Too many login attempts, please try again later.
n8sm185296pgd.31 - gsmtp
I went to my logs and found various LOGIN succeeded entries as well:
[root#thikiti ~]# cat /usr/share/apache-tomcat-7.0.73/logs/catalina.out | grep -i 'LOGIN succ' | wc -l
182
Is there a way to avoid re-authenticating each time an email is sent?
How do i authenticate password for the email id.Currently it is sending mail without authentication,so how do i authenticate password for mail.username given in propert file.
below code is there in spring-servlet :
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.host}" />
<property name="port" value="${mail.port}" />
<property name="username" value="${mail.username}" />
<property name="password" value="${mail.password}" />
<property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtps.auth">true</prop>
<prop key="mail.smtp.starttls.enable">false</prop>
<!-- <prop key="mail.smtp.debug">true</prop> -->
</props>
</property>
</bean>
**Mail Sending Part :**
SimpleMailMessage email = new SimpleMailMessage();
if(UserEmailId != null){
email.setFrom(userFrom);
email.setTo(UserEmailId);
email.setSubject(subject);
email.setText(MessageBody);
mailSender1.send(email);
}
**mail property file :**
#Email address/account for sending emails from system.
mail.username=<from email id>
#Password for accessing email account
mail.password=<password>
#Mail server hostname or IP
mail.host=<host>
#Mail server port
mail.port=25
#Mail transport protocol
mail.transport.protocol=smtp
#Mail authentication enabled true/false
mail.smtp.auth=true
#smtp TLS enable true/false
mail.smtp.starttls.enable=false
Set following true and try again
<prop key="mail.smtp.starttls.enable">true</prop>
Hope it helps
I am using SimpleMailMessage and MailSender in Spring to send mail. I have configured .xml file as
<bean id="mailSender" class ="org.springframework.mail.javamail.JavaMailSenderImpl" >
<property name="host" value="smtp.gmail.com" />
<property name="port" value="465" />
<property name="protocol" value="smtps"></property>
<property name="username" value="userId#gmail.com" />
<property name="password" value="passward" />
<property name="endoding" value="UTF-8"></property>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtps.auth">true</prop>
</props>
</property>
<bean id="userRegistrationService" class="UserRegistrationService">
<property name="mailSender" ref="mailSender" />
<property name="userEmailIds">
<set>
<value>abc#gmail.com</value>
<value>abc#yahoo.co.in</value>
</set>
</property>
</bean>
</bean>
but I get error :
Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required.
Learn more at
530 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 i7sm235670pbj.90
What could be the reason?
Did you check out the configuration guide on Google's site? You could for example try to set the mail port as 587 if 465 causes problems.
protocol is written smtps it should be smtp
I used the springmail to send email from my smtp server with the following config:
<bean id="springEmailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="defaultEncoding" value="UTF-8"/>
<property name="host" value="mail.myserver.com"/>
<property name="port" value="25"/>
<property name="username" value="username"/>
<property name="password" value="password"/>
<property name="javaMailProperties">
<value>
mail.debug=true
mail.smtp.auth=true
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.socketFactory.fallback=false
</value>
</property></bean>
But it throw "javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?"
I've tested this config with gmail on port 465 and it worked.
Please tell me what i've done wrong. Thank you
It looks like your SMTP server requires SSL (secure) connection. See example below of how to configure it for Gmail, which is also requires SSL. Note smtps protocol and extra properties.
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="port" value="465" />
<property name="protocol" value="smtps" />
<property name="username" value="user"/>
<property name="password" value="password"/>
<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>
</props>
</property>
</bean>
Maybe you shouldn't be using SSL. Is the mail server configured to accept an encrypted message? Looks like it wants plain text.
I'd go back to the reference docs and see if that will work.
I would try removing all javaMailProperties, as well as the username and password properties.
As duffymo points out, you probably shouldn't use SSL (port 25 is the non-SSL SMTP port). Most SMTP servers also don't require authentication (unless you've explicitly configured it).