Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Send Email

To send an email from MATLAB®, use the sendmail function. You can also attach files to an email, which lets you mail files directly from MATLAB. To use sendmail, set up your email address and your SMTP server information with the setpref function.

The setpref function defines two mail-related preferences:

  • Email address: This preference sets your email address that will appear on the message.

    setpref('Internet','E_mail','youraddress@yourserver.com');
    
  • SMTP server: This preference sets your outgoing SMTP server address, which can be almost any email server that supports the Post Office Protocol (POP) or the Internet Message Access Protocol (IMAP).

    setpref('Internet','SMTP_Server','mail.server.network');
    

Find your outgoing SMTP server address in your email account settings in your email client application. You can also contact your system administrator for the information.

Once you have properly configured MATLAB, you can use the sendmail function. The sendmail function requires at least two arguments: the recipient's email address and the email subject.

sendmail('recipient@someserver.com','Hello From MATLAB!');

You can supply multiple email addresses using a cell array of character vectors.

sendmail({'recipient@someserver.com','recipient2@someserver.com'}, ...
    'Hello From MATLAB!');

You can specify a message body.

sendmail('recipient@someserver.com','Hello From MATLAB!', ...
    'Thanks for using sendmail.');

You can attach files to an email.

sendmail('recipient@someserver.com','Hello from MATLAB!', ...
    'Thanks for using sendmail.','C:\yourFileSystem\message.txt');

You cannot attach a file without including a message. However, the message can be empty.

You can attach multiple files to an email.

sendmail('recipient@someserver.com','Hello from MATLAB!', ...
    'Thanks for using sendmail.',{'C:\yourFileSystem\message.txt', ...
    'C:\yourFileSystem\message2.txt'});

See Also

|

Was this topic helpful?