
% PSD3 special cruise email address:
mail = 'psd3cruise@gmail.com';    %PSD3 GMail email address
password = 'spyderman';           %password

%% Set up Gmail SMTP service.
% Note: following code found from http://www.mathworks.com/support/solutions/data/1-3PRRDV.html

setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',mail);
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');

%email recipient list
% emailto = {'ludovic.bariteau@noaa.gov','Daniel.Wolfe@noaa.gov','David.C.Welsh@noaa.gov','Sergio.Pezoa@noaa.gov','Chris.Fairall@noaa.gov'};
emailto = strcat('ludovic.bariteau@noaa.gov');

%subject
subject=(['Flux data - ', cruise, year, ' -  DOY', jd]);

%message content
% drtxt=dir(tpsd,'*.txt');
% drjpg=dir(tpsd,['*' graphformat]);
if report
    message=['Error issue in flux_eval from the ', ship, ' for DOY' , jd,...
        sprintf('\n %s',report)];
else
    message=['FTP of flux data from the ', ship, ' for DOY' , jd,...
        ' has been completed successfully. ',...
        num2str(length(entrynames)), ' file(s) zipped and transfered to voodoo\incoming\psd3\lbariteau\doy', ...
        jd, '\', cruise, year, '_flux_' jd '.zip', 10, ...
        sprintf('\t %s \n',entrynames{:})];
    
%     if ~isempty(drjpg)
%         message=['FTP of flux data from the ', ship, ' for DOY' , jd,...
%             ' has been completed successfully. Don''t worry, this is a test from Ludo. ',...
%             num2str(length(dr)), ' file(s) transfered on voodoo\incoming\psd3\lbariteau: ', 10 ...
%             sprintf('\t %s \n',drtxt.name),...
%             sprintf('\t %s \n',drjpg.name)];
%     else
%         message=['FTP of flux data from the ', ship, ' for DOY' , jd,...
%             ' has been completed successfully. Don''t worry, this is a test from Ludo. ',...
%             num2str(length(dr)), ' file(s) transfered on voodoo\incoming\psd3\lbariteau: ', 10 ...
%             sprintf('\t %s \n',drtxt.name)];
%     end;
end;

%% Send the email
sendmail(emailto,subject,message)
