sending E-mail error with outlook
43 ビュー (過去 30 日間)
古いコメントを表示
I am trying to send an email, using the MATLAB sendmail function.
% User input
source = 'aaaa@outlook.com'; %from address (gmail)
destination = 'bbbbb@outloook.com'; %to address (any mail service)
myEmailPassword = '123456'; %the password to the 'from' account
subj = 'This is the subject line of the email'; % subject line
msg = 'This is the main body of the email.'; % main body of email.
%set up SMTP service for Outlook
setpref('Internet','E_mail',source);
setpref('Internet','SMTP_Server','smtp.office365.com');
setpref('Internet','SMTP_Username',source);
setpref('Internet','SMTP_Password',myEmailPassword);
% Outlook server.
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.ssl.trust','smtp.office365.com');
props.setProperty('mail.smtp.user',source);
props.setProperty('mail.smtp.password',myEmailPassword);
props.setProperty('mail.smtp.host','smtp.office365.com');
props.setProperty('mail.smtp.port','587');
props.setProperty('mail.smtp.auth', 'false');
props.setProperty('mail.smtp.starttls.enable', 'true');
% Send the email
sendmail(destination,subj,msg);
While using this scritp code I am getting error :
Error using sendmail
530 5.7.57 Client not authenticated to send mail. [VI1PR08CA0229.eurprd08.prod.outlook.com
2023-10-03T15:18:10.674Z 08DBC23A7C55B27A]
Error in mail (line 25)
sendmail(destination,subj,msg);
What should I do for this error?
Thanks for helping.
0 件のコメント
回答 (2 件)
Ayush
2023 年 10 月 5 日
The ActiveX/COM interface can be used to control MS Outlook from MATLAB and send e-mails while using all the features available in MS Outlook. The function below is an example of how this can be done. Note that this function works almost the same as SENDMAIL.
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;
% multiple recipients
if length(to) > 1
to = strjoin(to,';')
endmail.To = to;
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;
Hope this helps!
2 件のコメント
Satoshi Furukawa
2023 年 10 月 25 日
Could you tell me how to create a body with forced line breaks.
For example, even if I set a line break text using the "newline" function,
it will be a single line on Outlook's email screen.
t_body = ("Line1 of message" + newline +"Line2 of message" + newline + "Line3 of message" )
t_body =
"Line1 of message
Line2 of message
Line3 of message"
[result]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1520801/image.png)
Chris Nygren
2023 年 12 月 12 日
Is this method of using
h = actxserver('outlook.Application');
mail = h.CreateItem('olMail');
etc
mail.Send;
h.release;
more reliable than using the sendolmail function? Using sendolmail, I've been inconsistantly getting this error 'ERROR: The process "outlook.exe" not found. '
Paul Furlow
2024 年 4 月 17 日
To work in R2024a, I changed the line
mail = h.CreateItem('olMail');
with the following:
mail = h.CreateItem('olMailItem');
1 件のコメント
Callum
2025 年 2 月 3 日 10:19
@Paul Furlow - Thanks very much for this answer. It's exactly what I was looking for after updating to a newer version!
参考
カテゴリ
Help Center および File Exchange で Web Services についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!