How to design a simple email client using App Designer in MATLAB?

This video explains the steps to create a simple email client interface using App Designer in MATLAB.

We will be glad to hear from you regarding any query, suggestions or appreciations at: programmerworld1990@gmail.com

Source code:

classdef Email_Client_ML < matlab.apps.AppBase

% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TOEditFieldLabel matlab.ui.control.Label
TOEditField matlab.ui.control.EditField
SubjectEditFieldLabel matlab.ui.control.Label
SubjectEditField matlab.ui.control.EditField
BodyTextAreaLabel matlab.ui.control.Label
BodyTextArea matlab.ui.control.TextArea
SendButton matlab.ui.control.Button
end

% Callbacks that handle component events
methods (Access = private)

% Button pushed function: SendButton
function SendButtonPushed(app, event)
setpref(‘Internet’,’SMTP_Server’,’smtp.gmail.com’);
setpref(‘Internet’,’E_mail’,’myemail@gmail.com’);

props = java.lang.System.getProperties;
props.setProperty(‘mail.smtp.auth’,’true’);
props.setProperty(‘mail.smtp.starttls.enable’,’true’);

setpref(‘Internet’,’SMTP_Username’,’myemail@gmail.com’);
setpref(‘Internet’,’SMTP_Password’,’**********’); % Need to give the password

sendmail(app.TOEditField.Value, app.SubjectEditField.Value, app.BodyTextArea.Value);

end
end

% Component initialization
methods (Access = private)

% Create UIFigure and components
function createComponents(app)

% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = ‘UI Figure’;

% Create TOEditFieldLabel
app.TOEditFieldLabel = uilabel(app.UIFigure);
app.TOEditFieldLabel.HorizontalAlignment = ‘right’;
app.TOEditFieldLabel.VerticalAlignment = ‘top’;
app.TOEditFieldLabel.Position = [26 425 27 15];
app.TOEditFieldLabel.Text = ‘TO: ‘;

% Create TOEditField
app.TOEditField = uieditfield(app.UIFigure, ‘text’);
app.TOEditField.Position = [68 421 529 22];

% Create SubjectEditFieldLabel
app.SubjectEditFieldLabel = uilabel(app.UIFigure);
app.SubjectEditFieldLabel.HorizontalAlignment = ‘right’;
app.SubjectEditFieldLabel.VerticalAlignment = ‘top’;
app.SubjectEditFieldLabel.Position = [26 379 52 15];
app.SubjectEditFieldLabel.Text = ‘Subject: ‘;

% Create SubjectEditField
app.SubjectEditField = uieditfield(app.UIFigure, ‘text’);
app.SubjectEditField.Position = [93 375 504 22];

% Create BodyTextAreaLabel
app.BodyTextAreaLabel = uilabel(app.UIFigure);
app.BodyTextAreaLabel.HorizontalAlignment = ‘right’;
app.BodyTextAreaLabel.VerticalAlignment = ‘top’;
app.BodyTextAreaLabel.Position = [26 310 36 15];
app.BodyTextAreaLabel.Text = ‘Body:’;

% Create BodyTextArea
app.BodyTextArea = uitextarea(app.UIFigure);
app.BodyTextArea.Position = [26 84 571 218];

% Create SendButton
app.SendButton = uibutton(app.UIFigure, ‘push’);
app.SendButton.ButtonPushedFcn = createCallbackFcn(app, @SendButtonPushed, true);
app.SendButton.Position = [497 28 100 22];
app.SendButton.Text = ‘Send’;

% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end

% App creation and deletion
methods (Access = public)

% Construct app
function app = Email_Client_ML

% Create UIFigure and components
createComponents(app)

% Register the app with App Designer
registerApp(app, app.UIFigure)

if nargout == 0
clear app
end
end

% Code that executes before app deletion
function delete(app)

% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

Leave a Reply

%d bloggers like this: