Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Please help with sendmail to multiple recipients

Subject: Please help with sendmail to multiple recipients

From: Mike Greene

Date: 12 Dec, 2013 13:45:09

Message: 1 of 7

Hello Group,

I am trying to set up sendmail to email multiple recipients at once. I can get sendmail to work for a single address but not for a cell array.

This works: mailto = 'xxx@hotmail.com'; %Recipient email addresses

However, I'd like to get something like this to work:

strArray = java_array('java.lang.String', 2);
strArray(1) = java.lang.String('xxx@hotmail.com');
strArray(2) = java.lang.String('yyy@hotmail.com');
mailto = cell(strArray);

Below is my code for a single address:

mailto = 'xxx@hotmail.com'; %Recipient email addresses
mailfrom = 'XXX@gmail.com'; %Your GMail email address
password = 'ZZZ'; %Your Gmail password
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','E_mail',mailto);
setpref('Internet','SMTP_Username',mailfrom);
setpref('Internet','SMTP_Password',password);
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(mailto,'Test from MATLAB','Hello! This is a test from MATLAB again!')

How do I properly set up the cell array for mailto to work with multiple addresses?

Subject: Please help with sendmail to multiple recipients

From: Steven Lord

Date: 12 Dec, 2013 15:41:55

Message: 2 of 7


"Mike Greene" <Spamnoway@aol.com> wrote in message
news:l8cel5$a70$1@newscl01ah.mathworks.com...
> Hello Group,
>
> I am trying to set up sendmail to email multiple recipients at once. I
> can get sendmail to work for a single address but not for a cell array.
> This works: mailto = 'xxx@hotmail.com'; %Recipient email addresses
>
> However, I'd like to get something like this to work:
>
> strArray = java_array('java.lang.String', 2);
> strArray(1) = java.lang.String('xxx@hotmail.com');
> strArray(2) = java.lang.String('yyy@hotmail.com');
> mailto = cell(strArray);

I don't know if SENDMAIL will accept a cell array containing an array of
Java strings. Why not use a regular cell array containing character arrays
(strings)?

mailto = {'xxx@hotmail.com', 'yyy@hotmail.com'}

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Please help with sendmail to multiple recipients

From: Mike Greene

Date: 12 Dec, 2013 19:24:06

Message: 3 of 7

"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <l8clg4$a34$1@newscl01ah.mathworks.com>...
>
> "Mike Greene" <Spamnoway@aol.com> wrote in message
> news:l8cel5$a70$1@newscl01ah.mathworks.com...
> > Hello Group,
> >
> > I am trying to set up sendmail to email multiple recipients at once. I
> > can get sendmail to work for a single address but not for a cell array.
> > This works: mailto = 'xxx@hotmail.com'; %Recipient email addresses
> >
> > However, I'd like to get something like this to work:
> >
> > strArray = java_array('java.lang.String', 2);
> > strArray(1) = java.lang.String('xxx@hotmail.com');
> > strArray(2) = java.lang.String('yyy@hotmail.com');
> > mailto = cell(strArray);
>
> I don't know if SENDMAIL will accept a cell array containing an array of
> Java strings. Why not use a regular cell array containing character arrays
> (strings)?
>
> mailto = {'xxx@hotmail.com', 'yyy@hotmail.com'}
>
> *snip*
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Steve,

Thanks for the response! If I change it to: mailto = {'xxx@hotmail.com', 'yyy@hotmail.com'}

I get the following error:

??? Error using ==> sendmail>getInternetAddress at 227

Error in ==> sendmail at 89
msg.setFrom(getInternetAddress(from));

Error in ==> emailtest at 18
sendmail(mailto,'Test from MATLAB','Hello! This is a test from MATLAB again!')

However, if I set it to: mailto = {'xxx@hotmail.com'}

it works just fine? Any ideas?

Subject: Please help with sendmail to multiple recipients

From: Steven Lord

Date: 13 Dec, 2013 15:25:00

Message: 4 of 7


"Mike Greene" <Spamnoway@aol.com> wrote in message
news:l8d2gm$3jp$1@newscl01ah.mathworks.com...
> "Steven Lord" <Steven_Lord@mathworks.com> wrote in message
> <l8clg4$a34$1@newscl01ah.mathworks.com>...

*snip*

> Steve,
>
> Thanks for the response! If I change it to: mailto = {'xxx@hotmail.com',
> 'yyy@hotmail.com'}
>
> I get the following error:
>
> ??? Error using ==> sendmail>getInternetAddress at 227
>
> Error in ==> sendmail at 89
> msg.setFrom(getInternetAddress(from));
>
> Error in ==> emailtest at 18
> sendmail(mailto,'Test from MATLAB','Hello! This is a test from MATLAB
> again!')
>
> However, if I set it to: mailto = {'xxx@hotmail.com'}
>
> it works just fine? Any ideas?

No, I'm not familiar enough with the Java underlying SENDMAIL to know
exactly what's wrong. I recommend you contact Technical Support and ask them
to help you investigate why the cell array of multiple addresses isn't
working, because according to the documentation it should.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Please help with sendmail to multiple recipients

From: Mike Greene

Date: 13 Dec, 2013 15:28:05

Message: 5 of 7

"Mike Greene" wrote in message <l8d2gm$3jp$1@newscl01ah.mathworks.com>...
> "Steven Lord" <Steven_Lord@mathworks.com> wrote in message <l8clg4$a34$1@newscl01ah.mathworks.com>...
> >
> > "Mike Greene" <Spamnoway@aol.com> wrote in message
> > news:l8cel5$a70$1@newscl01ah.mathworks.com...
> > > Hello Group,
> > >
> > > I am trying to set up sendmail to email multiple recipients at once. I
> > > can get sendmail to work for a single address but not for a cell array.
> > > This works: mailto = 'xxx@hotmail.com'; %Recipient email addresses
> > >
> > > However, I'd like to get something like this to work:
> > >
> > > strArray = java_array('java.lang.String', 2);
> > > strArray(1) = java.lang.String('xxx@hotmail.com');
> > > strArray(2) = java.lang.String('yyy@hotmail.com');
> > > mailto = cell(strArray);
> >
> > I don't know if SENDMAIL will accept a cell array containing an array of
> > Java strings. Why not use a regular cell array containing character arrays
> > (strings)?
> >
> > mailto = {'xxx@hotmail.com', 'yyy@hotmail.com'}
> >
> > *snip*
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > To contact Technical Support use the Contact Us link on
> > http://www.mathworks.com
>
> Steve,
>
> Thanks for the response! If I change it to: mailto = {'xxx@hotmail.com', 'yyy@hotmail.com'}
>
> I get the following error:
>
> ??? Error using ==> sendmail>getInternetAddress at 227
>
> Error in ==> sendmail at 89
> msg.setFrom(getInternetAddress(from));
>
> Error in ==> emailtest at 18
> sendmail(mailto,'Test from MATLAB','Hello! This is a test from MATLAB again!')
>
> However, if I set it to: mailto = {'xxx@hotmail.com'}
>
> it works just fine? Any ideas?

Hoping someone has some ideas to try on expanding mailto to more than i recipient?

Really stuck here and would prefer to avoid using a "for" loop? Thanks!

Subject: Please help with sendmail to multiple recipients

From: Steven Lord

Date: 16 Dec, 2013 02:59:53

Message: 6 of 7


"Mike Greene" <Spamnoway@aol.com> wrote in message
news:l8f925$bov$1@newscl01ah.mathworks.com...

*snip*

> Hoping someone has some ideas to try on expanding mailto to more than i
> recipient?

Yes: Technical Support. I believe what I posted _should_ work; they will be
able to help you determine why it didn't.

> Really stuck here and would prefer to avoid using a "for" loop? Thanks!

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Please help with sendmail to multiple recipients

From: Mike Greene

Date: 16 Dec, 2013 15:56:23

Message: 7 of 7

"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <l8lqba$35s$1@newscl01ah.mathworks.com>...
>
> "Mike Greene" <Spamnoway@aol.com> wrote in message
> news:l8f925$bov$1@newscl01ah.mathworks.com...
>
> *snip*
>
> > Hoping someone has some ideas to try on expanding mailto to more than i
> > recipient?
>
> Yes: Technical Support. I believe what I posted _should_ work; they will be
> able to help you determine why it didn't.
>
> > Really stuck here and would prefer to avoid using a "for" loop? Thanks!
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

In case anyone else iis interested, Dr. Jonathan LeSage of Matlab support provided me with the fix:

mailto = {'xxx@hotmail.com', 'yyy@hotmail.com'};
mailfrom = 'XXX@gmail.com';
password = 'ZZZ';
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','E_mail',mailfrom);
setpref('Internet','SMTP_Username',mailfrom);
setpref('Internet','SMTP_Password',password);
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(mailto,'Test from MATLAB','Hello! This is a test from MATLAB again!')

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us