NewMonk2Perl has asked for the wisdom of the Perl Monks concerning the following question:

Good morning gurus! I have searched the web and could not find if it would be possible to send an email through outlook which you can copy or attached a table into the body of the email. It would be a simple table but yet I would still need it to look nice(same as if I manually copied it from excel and pasted it into an outlook email). It's a small table and I really do not want to send it as an attachment since its just another step for the user.

I am assuming that the best way to do this is to use Win32::OLE and copy the cells and paste it into the email? I am currently using Mail::Outlook to send the email.

Is this even possible? If it is, could someone point me in the right direction? Thanks in advance.

Paul

Replies are listed 'Best First'.
Re: Outlook email with table
by marto (Cardinal) on Jan 24, 2011 at 15:22 UTC

    I think you're confused. Outlook is an email client which sends emails via a mail server. Cut out the middle man and use MIME::Lite to send the email via the same mail server, formatted however you require.

      So I will be able to copy a table from excel? I will take a look at it.

      Thanks again..

      Paul

        You mentioned you wanted it to "look nice(same as if I manually copied it from excel and pasted it into an outlook email)", at this point I wasn't sure if Excel was the source or if the 'table' came from somewhere else, for example an HTML table. It helps to be specific when asking a question.

        Regarding reading from Excel see Spreadsheet::ParseExcel, it's similar to Spreadsheet::WriteExcel which I introduced you to previously.

        MIME::Lite is a fairly low level module for creating e-mails that are MIME encoded. That means that, in addition to attachments, you can have the e-mail body be something other than plain text. If you want to send e-mails that are formatted, you're going to want to create an HTML e-mail. This is where you're going to have to do more than simply copy and paste in a MS Office appliction - you're going to need to do the equivalent of pasting your table into something (possibly Word) and save that as HTML. You'll then need to take the HTML table code and put it into the body of your e-mail. You're then going to have to write Perl code that sets the HTML for your e-mail body, for your table, and for any other information that you want in the e-mail. One very good HTML authoring site is SitePoint.com. They have an excellent guide on how to create good e-mail newsletters. Although you're not specifically creating a newsletter, the information still applies, because you're creating an HTML e-mail.

        PS: Even though I mention Word as a possible HTML creator, I only say that because it sounds like you have not written Perl code to generate e-mails before. Word's HTML formatting is complex, verbose, and from an HTML standards perspective quite bad.