MATLAB: Am I unable to use the SENDMAIL function in MATLAB to send emails to addresses outside the domain

MATLAB

I have set my SMTP Server and Email address as follows
setpref('Internet','SMTP_Server','myserver.com');
setpref('Internet','E_mail','me@aserver.com');
However, when I execute the SENDMAIL command
sendmail('me@hotmail.com','Test email', 'Test');
I receive the following error
??? Error using ==> sendmail>sendSMTP
SMTP error: 550 5.7.1 Unable to relay for me@hotmail.com
Error in ==> sendmail at 144
sendSMTP(out, in, ['RCPT TO: ' to], 1);

Best Answer

The error message you receive is due to the SMTP server name and the email address not belonging to the same domain.
Thus, the domain 'myserver.com' will prevent someone outside that domain, for example 'me@aserver.com', from sending e-mails. Email servers are typically set up this way in order to prevent e-mails from spammers.
In order to be able to successfully use the SENDMAIL command, ensure that the SMTP Server and email address belong to the same domain. For example
setpref('Internet','SMTP_Server','myserver.com');
setpref('Internet','E_mail','me@myserver.com');
Related Question