Main Content

sendmail

Send email message to address list

Description

sendmail(recipients,subject) sends an email to the specified recipients with the specified subject.

Note

sendmail does not support major email providers such as Gmail and Microsoft® Outlook®. sendmail only supports email servers with Basic username-password based authentication and Transport Layer Security (TLS) 1.0. For more information, see Set Preferences.

example

sendmail(recipients,subject,message) includes the specified message.

example

sendmail(recipients,subject,message,attachments) attaches the files listed in attachments.

example

Examples

collapse all

Send a message with two attachments to an email address:

sendmail('user@otherdomain.com',...
         'Test subject','Test message',...
         {'folder/attach1.html','attach2.doc'});

Send a message with forced line breaks (using 10) to an email address:

sendmail('user@otherdomain.com','New subject', ...
        ['Line1 of message' 10 'Line2 of message' 10 ...
         'Line3 of message' 10 'Line4 of message']);

The resulting message is:

Line1 of message
Line2 of message
Line3 of message
Line4 of message

Input Arguments

collapse all

Recipients of email, specified as a string scalar, string array, character vector, or cell array of character vectors. For a single recipient, specify recipients as a character vector or a string. For multiple recipients, specify recipients as a cell array of character vectors or a string array.

Subject line of email, specified as a string scalar or character vector.

Message text of email, specified as a string scalar, string array, character vector, or cell array of character vectors. If message is a character vector or a string, sendmail automatically wraps text at 75 characters. To force a line break in the message text, use 10. If message is a cell array of character vectors or a string array, then each element represents a new line of text.

sendmail does not support HTML-formatted messages. However, you can send HTML files as attachments.

Attached files, whose file paths are specified as a string scalar, string array, character vector, or cell array of character vectors.

More About

collapse all

Set Preferences

  • If sendmail cannot determine your email address or outgoing SMTP mail server from your system registry, specify those settings using the setpref function. For example:

    setpref('Internet','SMTP_Server','my_server.example.com');
    setpref('Internet','E_mail','my_email@example.com');

    To identify the SMTP server for the call to setpref, check the preferences for your email application, or consult your email system administrator. If you cannot easily determine the server name, try 'mail', which is a common default, such as:

    setpref('Internet','SMTP_Server','mail');
  • To override the default character encoding, set the preference for email character encoding as follows:

    setpref('Internet','E_mail_Charset',encoding); 
    where encoding is a character vector specifying the character encoding, such as 'SJIS'.

  • By default, the sendmail function does not support email servers that require authentication. To support these servers, change your system settings and set preferences for the SMTP user name and password, with commands in the following form:

    props = java.lang.System.getProperties;
    props.setProperty('mail.smtp.auth','true');
    
    setpref('Internet','SMTP_Username','myaddress@example.com');
    setpref('Internet','SMTP_Password','mypassword');

Tips

  • On Windows® systems with Microsoft Outlook, you can send email directly through Outlook by accessing the COM server with actxserver. For an example, see Solution 1-RTY6J.

Version History

Introduced in R2006a