MATLAB: Sendmail and attaching images

emailsendmail

I'm encountering a problem when using sendmail to include an image attachment. I have sendmail set up so that it works. When I have a plot, I can send it by typing the following in the command window
print(gcf,'-dpng','-r0','bargraph.png')
sendmail('fishbacp@mail.gvsu.edu','Bargraph from script attached','bargraph.png')
However, when I try to include the above lines within a script, the actual image is not attached. Instead, I receive the email but it merely has "bargraph.png" appearing as the message body.

Best Answer

Thank you so much. Am I correct that your code prompts the use to specify the attachment directory, as described below the line
%------------ Attach file ----------
I'm curious to know if there's a simpler way to do this so that I can let a script run for several hours (or couple of days) and then return to find that the image attachment has automatically been sent to my inbox.
Related Question