MATLAB: Multiple SMTP Servers for any type of email address

emailjavapromptpropertiessendmailserverssmtp

Hello I was wondering about a way to put in custom email addresses and smtp servers for various email service providers.
name_xls = num2str(filenamev1);
name_xls2 = [name_xls '.xls'];
xlswrite(name_xls, exceloutput, 'Sheet1','A1');
%Emails Excel sheet.

promptemail = menu( 'Email', 'Yes, email my results to my email!', 'No, I do not wish to email my results at this time.');
%Emails Excel sheet.
if promptemail==1
h = warndlg('Make sure your computer is connected to a secure Wifi connection! e.g: UCLA_WIFI, home network, etc. or disable your firewall!');
waitfor(h);
filepath = fullfile(pwd, name_xls2);
% Define a title for the dialog box
dialogtitle = 'Email Credentials';
% Define the labels for the individual entries
emailinfo = {'Email Address'};
% Create the dialog box with the inputdlg command
z = inputdlg(emailinfo, dialogtitle);
waitfor(z);
password = passcode;
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','E_mail',z{1});
setpref('Internet','SMTP_Username',z{1});
setpref('Internet','SMTP_Password',password);
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');
sendmail(z{1},['LFA Analysis for: ' num2str(filenamev1)] , 'Here are the results for your analysis!', filepath)
else
end
warndlg('Done!');

Best Answer

Yes. Just detect which email service provider you are using with strfind() and take action (set custom email addresses and smtp servers) based on which providers you find.