MATLAB: How to configure sendmail to use STARTTLS while sending email on port 587

MATLAB

My mail server only listens to port 587 and supports STARTTLS.
I would like to secure SMPT over TLS and use STARTTLS.
How do I do this?

Best Answer

In order to enable STARTTLS via port 587, use the following configuration example:
mail = 'your_email_address@example.com;    % Replace with your email address
password = 'your_password';          % Replace with your email password
server = 'smtp.example.com';     % Replace with your SMTP server
% Apply prefs and props
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.port', '587');
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.starttls.enable','true');
setpref('Internet','E_mail', mail);
setpref('Internet','SMTP_Server', server);
setpref('Internet','SMTP_Username', mail);
setpref('Internet','SMTP_Password', password);
% Send the email
sendmail('receipient_email_address@example.com', 'Test', 'Msg from MATLAB');