Clear Filters
Clear Filters

Getting the error : Exception reading response; Unrecognized SSL message, plaintext connection?

30 views (last 30 days)
UserName = 'email@gmail.com';
passWord = 'xxxxxx';
setpref('Internet','E_mail',UserName);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',UserName);
setpref('Internet','SMTP_Password',passWord);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory') ;
props.setProperty('mail.smtp.socketFactory.port','587');
emailto = 'email@xxx.com'; % recipient's email
sendmail(emailto, 'My Subject', 'My message');
Getting the error : Exception reading response;
Unrecognized SSL message, plaintext connection?
I know someone got the same problem (and it was almost the same topic), but I didn't find my solution on his topic ....

Answers (1)

Muskan
Muskan on 23 Sep 2024 at 11:52
Hi,
There generally two options of ports for outbound emails: 587 and 465.
Port 587 is the preferred mail submission port. It uses TLS encryption which needs STARTTLS to be enabled. Port 587 can be enabled with the following commands:
>> props = java.lang.System.getProperties;
>> props.setProperty('mail.smtp.starttls.enable','true');
>> props.setProperty('mail.smtp.port','587')
Port 465 was deprecated two years after its initiation, but it is still used to support legacy systems. Port 465 uses SSL encryption and can be enabled with the following commands:
>> props = java.lang.System.getProperties;
>> props.setProperty('mail.smtp.socketFactory.class','javax.net.ssl.SSLSocketFactory');
>> props.setProperty('mail.smtp.socketFactory.port','465');
When using Port 587 with TLS, make sure that 'mail.smtp.socketFactory.class' is not set to 'javax.net.ssl.SSLSocketFactory' which is the case here. The 'javax.net.ssl.SSLSocketFactory' can be unset by restarting MATLAB or by running either of the following functions:
>> props.setProperty('mail.smtp.socketFactory.class','');
>> props.remove('mail.smtp.socketFactory.class');
For additional debugging messages, add the following command:
>> props.setProperty('mail.debug','true');
Additionally, descriptions for the Java SMTP protocol package can be found in the following link: https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
I hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!