MATLAB Answers

Select my mail address to send mail by Outlook with Matlab

22 ビュー (過去 30 日間)
Adriano
Adriano 2017 年 4 月 6 日
Answered: Megan Morkes 2019 年 2 月 13 日
Hello, I'm using this function to send mail through Outlook with matlab:
function sendolmail(to,subject,body,attachments)
%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.Body = body;
%mail.BodyFormat = 'olFormatHTML';
%mail.HTMLBody = body;
% Add attachments, if specified.
if nargin == 4
for i = 1:length(attachments)
mail.attachments.Add(attachments{i});
end
end
% Send message and release object.
mail.Send;
h.release;
The problem is that I have two different mail addresses in Outlook. How can I specify from which mail to send?? Thanks!

  0 件のコメント

サインイン to comment.

採用された回答

wei bai
wei bai 2018 年 4 月 19 日

Try add this before mail.Send

mail.SentOnBehalfOfName = "example@email.com"; %change to the email you want send from

  0 件のコメント

サインイン to comment.

More Answers (1)

Megan Morkes
Megan Morkes 2019 年 2 月 13 日
Hi! I'm joining this thred because I'm using this code to send email - however it is getting stuck in my outbox and not fulling sending. Could you please advise? Thank you!

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。


Translated by