How can I simulate with SimKey sending an email?

1 view (last 30 days)
I am trying to send an email in Outlook and I get the message "A program is trying to send an email on your behalf", so this email cannot be automatically sent.
That's why I tried to simulate pressing the keys CTRL+ENTER in outlook, which means "send", but it's not working. Any idea? Thanks in advance.
This is the code:
function sendolmail(to,subject,body)
%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;
% Send message and release object.
mail.Display;
import java.awt.Robot;
import java.awt.event.*;
SimKey=Robot;
mail.Display;
pause(3)
SimKey.keyPress(KeyEvent.VK_CONTROL);
SimKey.keyPress(KeyEvent.VK_ENTER);
SimKey.keyRelease(KeyEvent.VK_CONTROL);
SimKey.keyRelease(KeyEvent.VK_ENTER);
% mail.Send; %This works but asks me to allow another program to send the email
h.release;
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!