Hello,
I use a code found on Mathworks.com to send mails via Outlook from my matlab code. The synthax to call this function is like sendmail(to, subject, body, attachment). The problem I have is that it does not accept cell array in my case ! Normally it should work. So for a text of several lines. The body = {'line 1', 'lin2', 'lin3'} is not accepted...
Could you help me please?
I am using Matlab 2010a, Win 7 pro and Outlook 2007.
Here is the code:
function sendolmail(to,subject,body,attachments)
%Sends email using MS Outlook. The format of the function is
%Similar to the SENDMAIL command.
% Create object and set parameters.
h = actxserver('outlook.Application');
mail = h.CreateItem('olMail');
mail.Subject = subject;
mail.To = to;
mail.BodyFormat = 'olFormatHTML';
mail.HTMLBody = body;
% Add attachments, if specified.
if nargin == 4
for i = 1:length(attachments)
mail.attachments.Add(attachments{i});
end
end
% Send message and release object.
mail.Send;
h.release;
|
|
0
|
|
|
|
Reply
|
Audric
|
2/27/2011 6:10:21 PM |
|
On 27/02/11 12:10 PM, Audric wrote:
> Hello,
>
> I use a code found on Mathworks.com to send mails via Outlook from my
> matlab code. The synthax to call this function is like sendmail(to,
> subject, body, attachment). The problem I have is that it does not
> accept cell array in my case ! Normally it should work. So for a text of
> several lines. The body = {'line 1', 'lin2', 'lin3'} is not accepted...
>
> Could you help me please?
>
> I am using Matlab 2010a, Win 7 pro and Outlook 2007.
>
> Here is the code:
>
> function sendolmail(to,subject,body,attachments)
> %Sends email using MS Outlook. The format of the function is %Similar to
> the SENDMAIL command.
>
> % Create object and set parameters.
> h = actxserver('outlook.Application');
> mail = h.CreateItem('olMail');
> mail.Subject = subject;
> mail.To = to;
> mail.BodyFormat = 'olFormatHTML';
> mail.HTMLBody = body;
>
> % Add attachments, if specified.
> if nargin == 4
> for i = 1:length(attachments)
> mail.attachments.Add(attachments{i});
> end
> end
>
> % Send message and release object.
> mail.Send;
> h.release;
I would point out that the cell array you are passing as the body is
*not* in HTML format, but the script expects it to be 'olFormatHTML'
|
|
0
|
|
|
|
Reply
|
Think
|
2/27/2011 6:32:55 PM
|
|
On Feb 27, 1:10=A0pm, "Audric " <audricdebaisi...@gmail.com> wrote:
> Hello,
>
> I use a code found on Mathworks.com to send mails via Outlook from my mat=
lab code. The synthax to call this function is like sendmail(to, subject, b=
ody, attachment). The problem I have is that it does not accept cell array =
in my case ! Normally it should work. So for a text of several lines. The b=
ody =3D {'line 1', 'lin2', 'lin3'} is not accepted...
>
> Could you help me please?
>
> I am using Matlab 2010a, Win 7 pro and Outlook 2007.
>
> Here is the code:
>
> function sendolmail(to,subject,body,attachments)
> %Sends email using MS Outlook. The format of the function is
> %Similar to the SENDMAIL command.
>
> % Create object and set parameters.
> h =3D actxserver('outlook.Application');
> mail =3D h.CreateItem('olMail');
> mail.Subject =3D subject;
> mail.To =3D to;
> mail.BodyFormat =3D 'olFormatHTML';
> mail.HTMLBody =3D body;
>
> % Add attachments, if specified.
> if nargin =3D=3D 4
> for i =3D 1:length(attachments)
> mail.attachments.Add(attachments{i});
> end
> end
>
> % Send message and release object.
> mail.Send;
> h.release;
the body has to be a string character. If you have multiple lines,
with each line as a char in a cell then instead of passing the cell
array pass this:
sprintf('%s\n', body{:})
which adds a newline to the end of each element of the body cell
array.
/reza
|
|
0
|
|
|
|
Reply
|
reza
|
2/27/2011 6:37:19 PM
|
|
Thanks for these quick replies.
With a combination of your two answers I manage to solve my problem.
Only strings are accepted with html tags. So the right thing to do is to place
For multiple lines body: 'line 1 <br /> line 2 <br /> line 3'.
For multiple recipients: 'recipient1; recipient2; recipient3'
Thanks and regards,
|
|
0
|
|
|
|
Reply
|
Audric
|
2/27/2011 7:11:04 PM
|
|
Hi, I have the same problem. Could you explain what you meant by :
or multiple lines body: 'line 1 <br /> line 2 <br /> line 3'
How did you change your code?
Thanks
Peter
|
|
0
|
|
|
|
Reply
|
ppl4world (5)
|
4/15/2011 11:49:20 PM
|
|
"Audric" wrote in message <ike42c$1vc$1@fred.mathworks.com>...
> Hello,
>
> I use a code found on Mathworks.com to send mails via Outlook from my matlab code. The synthax to call this function is like sendmail(to, subject, body, attachment). The problem I have is that it does not accept cell array in my case ! Normally it should work. So for a text of several lines. The body = {'line 1', 'lin2', 'lin3'} is not accepted...
>
> Could you help me please?
>
> I am using Matlab 2010a, Win 7 pro and Outlook 2007.
>
> Here is the code:
>
> function sendolmail(to,subject,body,attachments)
> %Sends email using MS Outlook. The format of the function is
> %Similar to the SENDMAIL command.
>
> % Create object and set parameters.
> h = actxserver('outlook.Application');
> mail = h.CreateItem('olMail');
> mail.Subject = subject;
> mail.To = to;
> mail.BodyFormat = 'olFormatHTML';
> mail.HTMLBody = body;
>
> % Add attachments, if specified.
> if nargin == 4
> for i = 1:length(attachments)
> mail.attachments.Add(attachments{i});
> end
> end
>
> % Send message and release object.
> mail.Send;
> h.release;
Like Peter, I would also like to know how you modified the sendolmail function to be able to send a cell array as the message body? Thank you in advance!
|
|
0
|
|
|
|
Reply
|
Tom.Cheng (2)
|
3/9/2012 4:58:12 PM
|
|
Here is my solution
% mailbody is my string with multiple lines, I need to send
mailbody = cellstr(mailbody) % to get a vector of 1 line string
mailbody2 = '';
for i = 1:numel(mailbody)
mailbody2 = cat(2, mailbody2, char(mailbody(i)), '<br />');
end
%Then you can send it with Sendolmail(to, mailsubject, mailbody, attachments)
|
|
0
|
|
|
|
Reply
|
audricdebaisieux (8)
|
3/9/2012 5:30:20 PM
|
|
"Audric" wrote in message <jjdenc$ks6$1@newscl01ah.mathworks.com>...
> Here is my solution
>
> % mailbody is my string with multiple lines, I need to send
>
> mailbody = cellstr(mailbody) % to get a vector of 1 line string
> mailbody2 = '';
> for i = 1:numel(mailbody)
> mailbody2 = cat(2, mailbody2, char(mailbody(i)), '<br />');
> end
>
> %Then you can send it with Sendolmail(to, mailsubject, mailbody, attachments)
Your code works flawlessly, thank you for your help Audric!
One thing I would say though is to make sure to pass the argument "mailbody2" instead of "mailbody" into the sendolmail function, for anyone else that's reading.
|
|
0
|
|
|
|
Reply
|
Tom.Cheng (2)
|
3/15/2012 2:31:35 PM
|
|
|
7 Replies
270 Views
(page loaded in 0.123 seconds)
Similiar Articles: Durbin Watson table or other test for autocorrelation of residuals ...Hello, I have following problem. I need to test serial ... Institute, Dept. of Fisheries and Oceans Canada %email ... Convert cell array to matrix to export that into ascii ... Intel Visual Fortran Error Message - comp.lang.fortranYou should not have to do anything to get this accepted - we fixed the ... NUMIAB=3D12) > > > still did not fix his problem ... Also, please send along an email address where ... Understanding Send-Q and Recv-Q by netstat - comp.os.linux ...... feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH... ... Swind and Rwind, not Send-Q, Recv-Q ... the highest subscript in the array?!? - comp.lang.idl ... You not ... How to convert characters to number - comp.lang.fortran... Good judgment comes from experience; email ... B when a='57.1234' or a='57.0' but not >>when a='57'. (snip) > Your problem is ... ASCII ... the 8-bit binary number and send ... Sending UDP packets over Ethernet - comp.arch.fpgaThe main problem it does have is that if you ... Due to the volume of email that I receive, I may not be able to reply to ... Sending a 2D Array in MPI - comp.parallel.mpi ... Iterating over a String - comp.lang.java.helpThe problem is more that in some circumstances where you ... come with filters that describe what chars they accept ... Concat string to cell array of strings - comp.soft-sys ... printing in bold and colors - comp.lang.java.helpHi all, I would like to print my results (arrays) to ... bold and colors - comp.lang.java.help How to get cell ... Forum - Windows ... hi, I'm using mailx to send an email with ... Sockets in gfortran? - comp.lang.fortran... servlisten_sockets} */ int serv_accept(int ... by regarding character strings as arrays of ... gfortran/gcc, but I ran into an odd problem with Intel Fortran: I can not ... How to check whether malloc has allocated memory properly in case ...... at the address returned, your problem is not ... and cyber computers and the fps array processors which had 64-bit words, not ... compilers I mostly used didn't accept ... Reverse engineering ASIC into FPGA - comp.arch.fpgaThe huge std cell arrays though have no ... process nodes, which can not be ecconmically obtained. We have exactly the same problem, as ... 884-7930 Fax 401/884-7950 email ... Problem to send email (cell array not accepted) - Newsreader ...Hello, I use a code found on Mathworks.com to send mails via Outlook from my matlab code. The synthax to call this function is like sendmail(to, subject, body ... How to Send a Text Message to a Verizon Phone | eHow.comVerizon Text Message Delay Problems. For about three years ... How to Send an Email to a Verizon Cell Phone Number. If you are not near a phone, but you are near a computer ... 7/21/2012 11:15:57 PM
|