Unable to call from jenkins to matlab using outlook api script

1 view (last 30 days)
Im able to run the outlook api using bellow matlab script.
But when running the same script from JENKINS Pipeline script via Batch script, it is throwing an error..
pipeline{
agent any
stages{
stage('Test Mail'){
steps{
bat returnStatus: true, returnStdout: true, script: '"C:\\Program Files (x86)\\MATLAB\\R2015b\\bin\\matlab.exe" -wait -sd "C:\\Users\\******\" -r "addpath(\'C:\\Users\\******\'); sendEmailWithOutlook(\'****@***.com\',\'Test mail\',\'Matlab sent you mail\', 0); quit;" -logfile "mailtest.txt"'
}
}
}
}
function sendEmailWithOutlook(emailAddress, subjectText, bodyText, Attach)
% sendEmailWithOutlook - Functions sends email to an email address,
% Microsoft Outlook has to be installed.
% emailAddress: Email address of the recipient
% subjectText: Message displayed in the subject line
% bodyText: Message displayed in the body of the email
% Attach: Path of Attachments
% Calling the function:
% sendEmailWithOutlook('xxx@domain.com', 'Testmail', 'This is a test!', 'c:\test.txt')
% It's possible to send without an attachment, then call function like this:
% sendEmailWithOutlook('xxx@domain.com', 'Testmail', 'This is a test!', 0)
% To have more than one recipient or attachment, use cell arrays like this:
% sendEmailWithOutlook({'xxx@domain.com', 'xxx@domain1.com'}, 'Testmail', 'This is a test!', {'c:\test.txt', 'D:\Test\readme.doc'} )
% Function was tested with Matlab 6.5 R13 on Windows XP Prof.
% with Outlook 2002
% Author: Rainer F., knallkopf66@uboot.com, Feb. 2004
try
disp('Started')
outlook = actxserver('Outlook.Application');
email = outlook.CreateItem(0);
if (iscell(emailAddress) == 1)
tmpSize = size(emailAddress);
for i = 1:tmpSize(2)
tmp = cell2mat(emailAddress(i));
email.Recipients.Add(tmp);
end
else
email.Recipients.Add(emailAddress);
end
email.Subject = subjectText;
email.Body = bodyText;
if (iscell(Attach) == 1)
tmpSize = size(Attach);
for i = 1:tmpSize(2)
tmp = cell2mat(Attach(i));
email.Attachments.Add(tmp);
end
else
if (Attach ~= 0)
email.Attachments.Add(Attach);
end
end
email.Send;
disp('Sent Mail')
catch e
disp(getReport(e,'extended'))
exit(1);
end
exit
  4 Comments
kishore babu kavuru
kishore babu kavuru on 6 Jun 2019
MException with properties:
identifier: 'MATLAB:COM:servercreationfailed'
message: 'Server Creation Failed: Call was rejected by callee.…'
cause: {0x1 cell}
stack: [2x1 struct]
kishore babu kavuru
kishore babu kavuru on 6 Jun 2019
under Stack::
'C:\Program Files\MATLAB\R2015b\toolbox\matlab\winfun\actxserver.m' 'actxserver' 86
'C:\Dinesh_LC\MOART\PullReqTesting\JenkinsData\sendEmailWithOutlook.m' 'sendEmailWithOutlook' 18

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!