View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Send email using CDO

4.5 | 6 ratings Rate this file 5 Downloads (last 30 days) File Size: 4.17 KB File ID: #29421 Version: 1.5
image thumbnail

Send email using CDO



16 Nov 2010 (Updated )

Send HTML formatted mail using the free Microsoft mail component CDO

| Watch this File

File Information

CDO stands for Collaboration Data Objects which ships with Windows 2000, Windows XP, and Windows Server 2003.

Find below different scenarii in which using emailtool_nodisplay may be interesting .

% Usage 1 :

 emailtool_nodisplay can be used to monitor usage of softwares in your company.
 Example in a GUI you can add these lines in the openingfcn:

% username = getenv('USERNAME');
% if isempty(username)
% str = '!whoami';
% username = deblank(evalc(str));
% end
% if ispc
% try %#ok<TRYNC>
% emailtool_nodisplay([mfilename ''],'','','',['used by ' username])
% end
% end

You will receive in your Microsoft Oulook Inbox an email letting you know that someone has started your software.

% Usage 2 :

 emailtool_nodsiplay can be used to receive notifications if a
code/simulation fails in a try-catch statement for example
You could make the exception message caught in the body message.

% Usage 3 :
 Can be used at the end of a successful compilation invoking MATLAB Compiler to automatically send a notification to your peers that a new code has been compiled.
You could send the verbose of mcc -mv in the body message.

% Usage 4 :

can be used to send emails from another sender (not advised except for joking!)

% Usage 5 :
can be used to send anonymous emails (idem not advised!)

- emailtool_nodisplay can send HTML messages.
- Messages can be sent to several recipients.

All the different syntaxes to run emailtool_nodisplay are documented in the header of M-file.

Example (shown in the screenshot) :
To receive an HTML email in both my Microsoft Outlook Inbox and my Yahoo Mail , I just typed:
>> from = '';
>> to = '';
>> CC = '';
>> subject = ['Mail sent via ' version('-release')];
>> attachments ={which('support'),which('why')};
>> messageHTML= ['<html>Please find enclosed the code of support .<br>' char(10),...
              '<b>This email has been sent by a MATLAB code created by Aurelien!!</b></html>'];
>> emailtool_nodisplay(from,to,CC,'',subject,messageHTML,attachments,1)

When running the above code , I receive an email with 2 attached files (see screenshot) . The last input argument of emailtool_nodisplay tells my code that I want to send an HTML message . It allows to have the last line of body message in bold in this example.

MATLAB release MATLAB 7.11 (R2010b)
Other requirements Microsoft outlook required. The first test performed in a try-catch statement is : >> h = actxserver('outlook.Application')
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
27 Sep 2016 Joe H

Joe H (view profile)

Excellent contribution thank you, still works under Matlab R2014b with the small adjustments Martin provides to use for an SMTP server.

09 Jan 2013 Martin

Martin (view profile)

09 Jan 2013 Martin

Martin (view profile)

I use a similar approach to send mails via the CDO API, inspired by this submission.

To set CDO SMTP settings, some lines like the following can be added after "mail = h.CreateObject('CDO.Message');"

hCdoConfig = h.CreateObject('CDO.Configuration');
hCdoConfig.Fields.Item('').set('Value', 2);
hCdoConfig.Fields.Item('').set('Value', '')
hCdoConfig.Fields.Item('').set('Value', 25);

mail.configuration = hCdoConfig;

More information on CDO settings (e.g. SMTP authorization) can be found in the MSDN library at

17 Oct 2012 Aurelien Queffurust

Still works under MATLAB 8.0
This utility is used in my company to monitor which software is most used.

01 Nov 2011 Jiong

Jiong (view profile)

Hi Aurelien,
Thank you for sharing. I tried your code on Matlab 2010b with WinXP and Outlook 2007. The mail email was not sent. Here is the error msg:
The email has not been sent:
Invoke Error, Dispatch Exception:
Source: CDO.Message.1
Description: The "SendingUing" configuration value is invalid."

Would you mind giving any suggestion on this. I really want a way to send html email through Matlab without manually allowing in Outlook.

Thanks a lot!


01 Nov 2011 Jiong

Jiong (view profile)

16 Nov 2010 1.1

Adding some comments in description about implemented features and syntax.

17 Nov 2010 1.4

Add a screenshot

30 Nov 2010 1.5

I 've just changed the title (was the M-file name before)

Contact us