View License

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

» Watch video

Highlights from

3.0 | 1 rating Rate this file 6 Downloads (last 30 days) File Size: 2.26 KB File ID: #28919 Version: 1.1




01 Oct 2010 (Updated )

a reasonably secure wrapper for sendmail that configures, and deletes, settings for gmail servers

| Watch this File

File Information

The MATLAB function sendmail will not work with a gmail account without some modification. The problem is that gmail server uses secure authentication and requires a user and password and some changes to the port and SSL settings. The doc page for sendmail (R2010b and later) explains how to do this. Two obvious problems are: (1) the preferences where username and password are saved are persistent between sessions and kept in an unsecure file on your hard drive - a bad idea. (2) the port and SSL setting are not persistent and need to be reset for each MATLAB session - annoying. GMAIL acts as a wrapper to sendmail that sets these values, sends an email, and then erases the user and password values. It is not ultra-secure but at least your password is not saved in a plain text file. Keep in mind though that your password string now exists in the command history! So an optional last argument allows you to delete the command history file after completion. (Note: I don't know how to delete just the last command without a long edit of the file.)

Call for comments: if you can think of another place where the password may be saved after running this function please let me know in the comments. Thanks.

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
20 Oct 2016 Naor Movshovitz

This function became obsolete shortly after it was submitted. The ML function email works fine with gmail accounts now, taking only a couple of simple setpref commands which are well documented. I am going to leave this FEX submission here for another month and then remove it, because I think it is now doing more harm than good.

Comment only
19 Oct 2016 Arda Aksu

it doesn't work anymore

06 May 2014 Thierry Dalon

Maybe the error
Could not connect to SMTP host:, port: 25;
Connection timed out: connect
occurs because we are behind a proxy.
And see

Comment only
01 Nov 2011 Francesco

I also get this error:

Could not connect to SMTP host:, port: 25;
Connection refused: connect

I can use the script to send email from my home computer but not from the office. Same Matlab and Windows version. Any idea?


Comment only
19 Oct 2011 Naor Movshovitz

Chandra, I was unable to reproduce that error. On all machines and configurations I have access to, the emails are sent without a problem. Perhaps there is some setting on your gmail account that prevents outgoing emails from other sources? On my gmail account settings page, under the Forwarding and POP/IMAP tab, I have IMAP enabled. See if that helps.

good luck.

Comment only
18 Oct 2011 Chandra Kurniawan

??? Error using ==> sendmail at 164
Exception reading response;
Connection reset

Error in ==> gmail at 26

Can U Help me??

Comment only
20 Jul 2011 Naor Movshovitz

John, I am not getting an error message and my emails are going through same as always. Can you give me a Matlab release and OS that generate the error?

Comment only
18 Jul 2011 John Fuller

John Fuller (view profile)

Like other functions of similar purpose I've found, the following error message comes up:

Could not connect to SMTP host:, port: 25;
Connection refused: connect

I found this by removing the clc from this function. I'm assuming Gmail has put in some changes that make these no longer functional.

Comment only
27 Jun 2011 Stan Young

Thank you for the function. It is needed. Are there any functions to retrieve headers or text from IMAP or POP3 servers that anyone is aware of?

Comment only
16 Oct 2010 Naor Movshovitz

Good catch Gary. Thanks. Revised file uploaded.

Comment only
15 Oct 2010 Gary

Gary (view profile)

Your regexp to check whether the sender email address is valid does not allow for email addresses with numbers in them.

Comment only
06 Oct 2010 Naor Movshovitz

That's a good idea. Thank you Jan.

Comment only
06 Oct 2010 Jan Simon

Jan Simon (view profile)

You can use one of the numerous password input dialogs from the FEX to ask for the password once in a Matlab session. Or you can save the password encrypted with one of the AES function from the FEX. The key for encryption can be stored in a P-coded function, but then additional obfuscation is needed to impede reading the variables with the debugger... At least no clear text password and no history deleting.

Comment only
16 Oct 2010 1.1

Fixed reg exp check of valid email string to allow numbers and _ and .edu emails.

Contact us