Select my mail address to send mail by Outlook with Matlab

조회 수: 4 (최근 30일)
Adriano
Adriano 2017년 4월 6일
댓글: DELMER Alexis 2023년 1월 4일
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!

채택된 답변

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
  댓글 수: 2
Mariano
Mariano 2022년 11월 24일
편집: Mariano 2022년 11월 24일
Hello,
I have tried this, but it does not work. It tries to send an email from myMainAdress@domain.com on behalf of myOtherAdress@domain.com (which is not what I want). But domain.com does not allow that.
Where can I find which are the allowed properties for the mail? I tried mail.SedUsingAccount = 'myOtherAddress@domain.com', but it says "Parameter must be a handle."
Thanks,

댓글을 달려면 로그인하십시오.

추가 답변 (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!

카테고리

Help CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by