for en engineering class i need to create a function that will send an email when under specific conditions, this is what ive written so far but it keep getting the error 'to many outputs'

1 view (last 30 days)
function [m,s] = Door_Status(x)
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','E_mail','myuser@gmail.com');
setpref('Internet','SMTP_Username','myuser');
setpref('Internet','SMTP_Password','mypassword');
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','465');
if x==true
m = sendmail('recipiant@gmail.com','Door Status Update Code','true') ;
elseif x==false
s = sendmail('recipiant@gmail.com','Door Status Update Code','true') ;
end
end

Accepted Answer

Walter Roberson
Walter Roberson on 6 Oct 2019
sendmail() does not return a value.
Question: why are you sending the same message for x true as for x false?
  2 Comments
Nathan Fischbach
Nathan Fischbach on 6 Oct 2019
i was just attempting to get something to send and i thought the problem could have been with what im sending so i made them the same. if send mail does not return a value how could i get an email to send? whould i have to use a loop?
Walter Roberson
Walter Roberson on 6 Oct 2019
sendmail() causes the message to be sent. It does not "prepare" a message to be sent with some later "yes, send it now" trigger: it does the sending.

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 6 Oct 2019
The documentation for the sendmail function does not list any syntax that has an output argument. Eliminate the output arguments from your calls to sendmail. You're probably also going to want to eliminate the output arguments from your function declaration line.
You also might want to check the text of the messages you're sending. I think you expect it to be different based on what the input is, but it's not.

Products

Community Treasure Hunt

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

Start Hunting!