Send Emails from GUI

8 次查看(过去 30 天)
Zainab Riyadh
Zainab Riyadh 2023-5-23
评论: Adam Danz 2023-5-24
Hello,
I have a GUI where I used exportapp to save a uifigure to pdf file :
exportapp(fig1, 'info1.pdf')
Then, I found the following function file in Matlab, which can send emails. I tried using it in a Script file to send a pdf file and it worked. However, when I shift to GUI and try using the function to send the pdf generated from exportapp, it doesn't work. Though, I get the pdf saved on my pc.
This is the function file:
function sendolmail(to,subject,body,attachments)
%Sends email using MS Outlook. The format of the function is
%Similar to the SENDMAIL command.
% Create object and set parameters.
h = actxserver('outlook.Application');
mail = h.CreateItem('olMail');
mail.Subject = subject;
mail.To = to;
mail.BodyFormat = 'olFormatHTML';
mail.HTMLBody = body;
% Add attachments, if specified.
if nargin == 4
for i = 1:length(attachments)
mail.attachments.Add(attachments{i});
end
end
% Send message and release object.
mail.Send;
h.release;
end
This code is used to send the email:
sendolmail('Email Address','Summary Report',{'C:\info1.pdf' });

回答(1 个)

the cyclist
the cyclist 2023-5-24
I don't know the answer to your question, but you might have better luck using the MATLAB-supplied sendmail function, rather than that quite old File Exchange function.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by