Quantcast

Documentation Center

  • Trial Software
  • Product Updates

sendmail

Send email message to address list

Syntax

sendmail(recipients,subject)
sendmail(recipients,subject,message)
sendmail(recipients,subject,message,attachments)

Description

sendmail(recipients,subject) sends email to recipients with the specified subject. The recipients input is a string for a single address, or a cell array of strings for multiple addresses.

sendmail(recipients,subject,message) includes the specified message. If message is a string, sendmail automatically wraps text at 75 characters. To force a line break in the message text, use 10, as shown in the Examples. If message is a cell array of strings, each cell represents a new line of text.

sendmail(recipients,subject,message,attachments) attaches the files listed in the string or cell array attachments.

Examples

Send a message with two attachments to a hypothetical 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 a hypothetical 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
 

Gmail™ servers require authentication and an encrypted connection (SSL) on port 465. Change your system settings to use your Gmail server and send a test message to your Gmail account:

% Modify these two lines to reflect
% your account and password.
myaddress = 'myaddress@gmail.com';
mypassword = 'mypassword';

setpref('Internet','E_mail',myaddress);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',myaddress);
setpref('Internet','SMTP_Password',mypassword);

props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', ...
                  'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');

sendmail(myaddress, 'Gmail Test', 'This is a test message.');

Alternatives

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.

More About

expand all

Tips

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

  • 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 electronic mail 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');
  • 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');
  • 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 string specifying the character encoding, such as 'SJIS'.

See Also

|

Was this topic helpful?