Can I send e-mail through MATLAB using Microsoft Outlook?

90 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2013 年 3 月 5 日
編集済み: MathWorks Support Team 2025 年 3 月 26 日
I want to send e-mail through MATLAB, but the SENDMAIL command does not save the outgoing message for future reference. I would like to send mail through MS Outlook so that I may reference it later.

採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 3 月 26 日
編集済み: MathWorks Support Team 2025 年 3 月 26 日
NOTE: This method is not compatible with "New Outlook" which no longer supports ActiveX.
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('olMailItem'); mail.Subject = subject; % multiple recipients if length(to) > 1 to = strjoin(to,';') end mail.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;
Examples of how to use this function would be the following:
The first will example includes a link, the second a picture.
sendolmail('test@mathworks.com','Test link','Test message including a <A HREF=http://www.mathworks.com>Link</A>', {'C:\attachment1.txt' 'C:\attachment2.txt'}); sendolmail('test@mathworks.com','Test image', 'Test message including an image <img src="http://t3.gstatic.com/images?q=tbn:ANd9GcQ-g_C_RAP7xbdz_Da-GK20YeycTzN2JkZotcIgx22dH2v4cBULmhVdLnc">', {})
Alternatively, you can use SENDMAIL but BCC the e-mail to yourself so that you may retain a copy.
  4 件のコメント
Angelo Yeo
Angelo Yeo 2023 年 6 月 1 日
Hi Michael,
Unfortunately, COM functions are available on Microsoft Windows® systems only.
Lily Yan
Lily Yan 2024 年 12 月 25 日
FYI:
I used
mail = h.CreateItem('olMailItem');
Instead of
mail = h.CreateItem('olMail');

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWeb Services についてさらに検索

製品


リリース

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by