1

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.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Abhay
  • 314
  • 1
  • 2
  • 11
  • Why are you using the mule4 tag if the issue is pure Java/Spring/javamail? – aled Oct 05 '22 at 11:30
  • You think they are valid but they aren't else you wouldn't get the exception. Are the placeholders actually being replaced with the values you have set? – M. Deinum Oct 05 '22 at 11:31
  • Yes, I can see in DEBUG logs, values are being replaced properly. Have tried hardcoding also. – Abhay Oct 05 '22 at 12:09
  • aled - I have tried the same in Mule also that's why. Hoping if someone has faced the same issue then they might be able to help – Abhay Oct 05 '22 at 12:10
  • It should only have ssl or starttls only not both. ssl is old and starttls is new encryption. Can you try with port 587 (With TLS/SSL)? – Dhaval Gajjar Oct 05 '22 at 12:19
  • I removed SSL and tried. Got this error - Error while sending email: Got bad greeting from SMTP host: smtp.mail.com, port: 465, response: [EOF] – Abhay Oct 05 '22 at 12:28
  • You are not configuring TLS correctly for the Mule 4 SMTP connector. You should not do it using Javamail properties but the connector configurations. Read the documentation. Probably it is not the cause of your issue though, since you are getting an answer from the server. – aled Oct 05 '22 at 13:48

0 Answers0