Matlab Send Email

I have interesting with how to send email from Matlab. This is a simple code how to send email from Matlab using Yahoo mail. You can change the host server name and port to other if want use other email host. Try to search at search engine to get smtp and port from other email.

function sendMessage(senderAddress, senderPassword, receiverAddress, ...
    m_subject, m_text)
% senderAddress   : sender email address (use Yahoo mail)
% senderPassword  : sender email password)
% receiverAddress : receiver email or phone number
% m_subject       : message subject
% m_text          : text message
% How to use :
% sendMessage('', 'yourpassword', 'email/phone number', 'subject', 'your message');
host = '';
port  = '465';

setpref( 'Internet','E_mail', senderAddress );
setpref( 'Internet', 'SMTP_Server', host );
setpref( 'Internet', 'SMTP_Username', senderAddress );
setpref( 'Internet', 'SMTP_Password', senderPassword );

props = java.lang.System.getProperties;
props.setProperty( 'mail.smtp.user', senderAddress );
props.setProperty( '', host );
props.setProperty( 'mail.smtp.port', port );
props.setProperty( 'mail.smtp.starttls.enable', 'true' );
props.setProperty( 'mail.smtp.debug', 'true' );
props.setProperty( 'mail.smtp.auth', 'true' );
props.setProperty( 'mail.smtp.socketFactory.port', port );
props.setProperty( 'mail.smtp.socketFactory.class', '' );
props.setProperty( 'mail.smtp.socketFactory.fallback', 'false' );

sendmail( receiverAddress , m_subject, m_text );

We can use this function (send email from Matlab using Yahoo mail) using command :

sendMessage('', 'yourpassword', 'email/phone number', 'subject', 'your message');

Add a Comment

Your email address will not be published. Required fields are marked *