MATLAB Answers

MATLAB email body include text and a table

7 views (last 30 days)
Hello everyone,
I would like to include into an email body apart from text, also a table.
For example:
This is a test email
'Alberta' '2020-07-20 00:00:00.0' '2021-05-03 00:00:00.0' 'no action needed' 'no action needed'
'Aristarchos' '2017-09-14 00:00:00.0' '2020-12-12 00:00:00.0' 'no action needed' 'action needed'
'Balos' '2018-05-22 00:00:00.0' '2020-12-20 00:00:00.0' 'no action needed' 'no action needed'
I tried to modify the sendmail function with below code:
~isempty(charset)
msg.setText(body, charset, 'html');
else
msg.setText(body, '', 'html'); %not sure an empty charset will work
end
but the result was that I couln't add the text only the table but not with the required format but simple single rows as per below:
Alberta
Aristarchos
Balos
2020-07-20 00:00:00.0
2017-09-14 00:00:00.0
2018-05-22 00:00:00.0
2021-05-03 00:00:00.0
2020-12-12 00:00:00.0
2020-12-20 00:00:00.0
no action needed
no action needed
no action needed
no action needed
action needed
no action needed
How can I achieve the required format?
Thank you in advance!!

Accepted Answer

Geoff Hayes
Geoff Hayes on 20 May 2021
  • The sendmail function does not support HTML-formatted messages. However, you can send HTML files as attachments.
So you might want to try converting your cell array into an HTML table and attach that to your message. Else, you could try converting each row of your cell array into a single string and include that in your message body (assuming that the text is no longer than 75 characters, I think that it all should be written to one line in the message).

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by